2011-01-21 31 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可以連接到)動態獲取數據,甚至可以合併來自多個數據庫的數據,您的報告只需要數據(記錄集),報告將使用數據創建字段定義。

相關問題