lucia
Sep 29th, 2008, 12:13 PM
I am using Crystal Report 9 and vb6 with Sql server 2000 as backend.
I have a report work perfectly on one server. Now I need to change it to work on different servers.
The fields are selected from 4 tables on design mode. In vb code, it set criteria to select the records to display.
Here is the original code to run on current server.
strReport = "\Overrides.rpt"
strSelection = "{TRANS.TRANDATE} = DateTime (" & Format(dtpDate.Value, "yyyy") & "," & Format(dtpDate.Value, "mm") & "," & Format(dtpDate.Value, "dd") & ", 00, 00, 00) and "
strSelection = strSelection & "{TRANS.ROUTE_NUM} = '" & gsCheckinRouteNum & "' and "
strSelection = strSelection & " {TRANS.PACKET_NUM} <> '' "
If cmbBranch.Text <> "ALL" Then
strSelection = strSelection & "and {Person.Per_Branch} = '" & cmbBranch.Text & "' "
End If
Set crReport = crApp.OpenReport(gsTrack & "\Reports\" & strReport)
crReport.RecordSelectionFormula = strSelection
If optPrint(0).Value = True Then
' Print to screen
frmCR9Report.Visible = False
frmCR9Report.CRV9.ReportSource = crReport
frmCR9Report.CRV9.ViewReport
frmCR9Report.CRV9.EnableGroupTree = False
frmCR9Report.Show vbModal
Set frmCR9Report = Nothing
Else
crReport.PrintOut False, 1
End If
Now I need change it able to connect to different server,
I added codes (in red), but didn't get the same result.
strReport = "\Overrides.rpt"
' Set the connection to the SQL database that we will pass to the report
strConnection = "Driver={SQL Server};" & _
"Server=" & gsTrackingSQL & ";" & _
"Database=" & gsTrackDatabaseName & ";" & _
"Uid=" & gstrTrkUsr & ";" & _
"Pwd=" & gstrTrkPwd
strSelection = "{TRANS.TRANDATE} = DateTime (" & Format(dtpDate.Value, "yyyy") & "," & Format(dtpDate.Value, "mm") & "," & Format(dtpDate.Value, "dd") & ", 00, 00, 00) and "
strSelection = strSelection & "{TRANS.ROUTE_NUM} = '" & gsCheckinRouteNum & "' and "
strSelection = strSelection & " {TRANS.PACKET_NUM} <> '' "
If cmbBranch.Text <> "ALL" Then
strSelection = strSelection & "and {Person.Per_Branch} = '" & cmbBranch.Text & "' "
End If
Set crReport = crApp.OpenReport(gsTrack & "\Reports\" & strReport)
Set adoRS = New ADODB.Recordset
adoRS.Open "Trans", strConnection, adOpenDynamic, adLockBatchOptimistic
crReport.Database.Tables(1).SetDataSource adoRS, 3
crReport.RecordSelectionFormula = strSelection
If optPrint(0).Value = True Then
' Print to screen
frmCR9Report.Visible = False
frmCR9Report.CRV9.ReportSource = crReport
frmCR9Report.CRV9.ViewReport
frmCR9Report.CRV9.EnableGroupTree = False
frmCR9Report.Show vbModal
Set frmCR9Report = Nothing
Else
crReport.PrintOut False, 1
End If
Could any one point out what's wrong in my code? Thanks a lot.
I have a report work perfectly on one server. Now I need to change it to work on different servers.
The fields are selected from 4 tables on design mode. In vb code, it set criteria to select the records to display.
Here is the original code to run on current server.
strReport = "\Overrides.rpt"
strSelection = "{TRANS.TRANDATE} = DateTime (" & Format(dtpDate.Value, "yyyy") & "," & Format(dtpDate.Value, "mm") & "," & Format(dtpDate.Value, "dd") & ", 00, 00, 00) and "
strSelection = strSelection & "{TRANS.ROUTE_NUM} = '" & gsCheckinRouteNum & "' and "
strSelection = strSelection & " {TRANS.PACKET_NUM} <> '' "
If cmbBranch.Text <> "ALL" Then
strSelection = strSelection & "and {Person.Per_Branch} = '" & cmbBranch.Text & "' "
End If
Set crReport = crApp.OpenReport(gsTrack & "\Reports\" & strReport)
crReport.RecordSelectionFormula = strSelection
If optPrint(0).Value = True Then
' Print to screen
frmCR9Report.Visible = False
frmCR9Report.CRV9.ReportSource = crReport
frmCR9Report.CRV9.ViewReport
frmCR9Report.CRV9.EnableGroupTree = False
frmCR9Report.Show vbModal
Set frmCR9Report = Nothing
Else
crReport.PrintOut False, 1
End If
Now I need change it able to connect to different server,
I added codes (in red), but didn't get the same result.
strReport = "\Overrides.rpt"
' Set the connection to the SQL database that we will pass to the report
strConnection = "Driver={SQL Server};" & _
"Server=" & gsTrackingSQL & ";" & _
"Database=" & gsTrackDatabaseName & ";" & _
"Uid=" & gstrTrkUsr & ";" & _
"Pwd=" & gstrTrkPwd
strSelection = "{TRANS.TRANDATE} = DateTime (" & Format(dtpDate.Value, "yyyy") & "," & Format(dtpDate.Value, "mm") & "," & Format(dtpDate.Value, "dd") & ", 00, 00, 00) and "
strSelection = strSelection & "{TRANS.ROUTE_NUM} = '" & gsCheckinRouteNum & "' and "
strSelection = strSelection & " {TRANS.PACKET_NUM} <> '' "
If cmbBranch.Text <> "ALL" Then
strSelection = strSelection & "and {Person.Per_Branch} = '" & cmbBranch.Text & "' "
End If
Set crReport = crApp.OpenReport(gsTrack & "\Reports\" & strReport)
Set adoRS = New ADODB.Recordset
adoRS.Open "Trans", strConnection, adOpenDynamic, adLockBatchOptimistic
crReport.Database.Tables(1).SetDataSource adoRS, 3
crReport.RecordSelectionFormula = strSelection
If optPrint(0).Value = True Then
' Print to screen
frmCR9Report.Visible = False
frmCR9Report.CRV9.ReportSource = crReport
frmCR9Report.CRV9.ViewReport
frmCR9Report.CRV9.EnableGroupTree = False
frmCR9Report.Show vbModal
Set frmCR9Report = Nothing
Else
crReport.PrintOut False, 1
End If
Could any one point out what's wrong in my code? Thanks a lot.