2011-01-21 33 views
1

我有一个VB6前端,SQL Server 2005作为后端,Crystal Reports 8.5作为报告。crystal reports 8 - 在vb6中动态设置位置

我需要在运行时在我的应用程序中设置位置,因为我有2个数据库。我的问题是,当我更改数据库时,但位置保持不变。如果有人能帮助我,那将是非常棒的。预先感谢您的时间,这里是我的代码。

Private Sub prin_Click() 
With CrystalReport1 
    .Connect = MDI1.txtcn --> this is my connection info "driver={sql server};server=server;database=database;uid=user;pwd=password"   
    .DiscardSavedData = True 
    .Action = 1 
    .PrintReport 
End With 
+0

+1为清楚起见。欢迎来到SO。 – PowerUser 2011-01-24 13:59:15

+0

为了我自己的知识,你使用了什么CR库? CRAXDDRT.dll? CRAXDRT.dll? – PowerUser 2011-01-24 14:16:52

回答

0

尝试格式化连接字符串是这样的:

DSN=server;UID=database;PWD=password;DSQ=user

DSN的含义,UIDDSQ是反直觉的,它们是由水晶超载。

同时检查您没有子报告,其Connect属性需要进行类似的更改。

2

尝试一些像这样的代码:

Private Sub cmdSetLocations_Click() 
    Dim CrxApp As New CRAXDRT.Application 
    Dim CrxRep As CRAXDRT.Report 
    Dim CrxSubRep As CRAXDRT.Report 

    Dim strReport As String 
    Dim i As Integer, ii As Integer 

    strReport = "[Path to report file]" 
    Set CrxRep = CrxApp.OpenReport(strReport) 

    SetReportLocation CrxRep 

    For i = 1 To CrxRep.Sections.Count 
     For ii = 1 To CrxRep.Sections(i).ReportObjects.Count 
      If CrxRep.Sections(i).ReportObjects(ii).Kind = crSubreportObject Then 
       Set CrxSubRep = CrxRep.OpenSubreport(CrxRep.Sections(i).ReportObjects(ii).SubreportName) 
       SetReportLocation CrxSubRep 
      End If 
     Next ii 
    Next 

    'open your report in the report viewer 

    Set CrxApp = Nothing 
    Set CrxRep = Nothing 
    Set CrxSubRep = Nothing 
End Sub 

Private Sub SetReportLocation(ByRef RepObj As CRAXDRT.Report) 
    Dim CrxDDF As CRAXDRT.DatabaseTable 
    Dim CP As CRAXDRT.ConnectionProperties 

    For Each CrxDDF In RepObj.Database.Tables 
     Set CP = CrxDDF.ConnectionProperties 
     CP.DeleteAll 
     CP.Add "Connection String", "[Your connection string goes here]" 
    Next 

    Set CrxDDF = Nothing 
    Set CP = Nothing 

End Sub 
1
With CR 
    .ReportFileName = App.Path + "\Labsen2.rpt" 
    .SelectionFormula = "{PersonalCalendar.PersonalCalendarDate}>= Date(" & Year(DTPicker1) & "," & Month(DTPicker1) & "," & Day(DTPicker1) & ") and {PersonalCalendar.PersonalCalendarDate}<=date(" & Year(DTPicker2) & "," & Month(DTPicker2) & "," & Day(DTPicker2) & ") and {Department.DepartmentName}= '" & Combo1.Text & "'" 
    .Formulas(0) = "tglAwal = '" & DTPicker1.Value & "'" 
    .Formulas(1) = "tglAkhir = '" & DTPicker2.Value & "'" 
    .Password = Chr(10) & "ithITtECH" 
    .RetrieveDataFiles 
    .WindowState = crptMaximized 
    .Action = 1 
End With 
0

为什么不记录传递到您的报告?通过这种方式,您将能够从任何支持的数据库(我的意思是VB6可以连接到)动态获取数据,甚至可以合并来自多个数据库的数据,您的报告只需要数据(记录集),报告将使用数据创建字段定义。

相关问题