Hi All,
Im using VB6 SP6 and CR XII with SP2.
I want to be able to set the database path in vb code to pass to the crystal report.
I have done a search on the forum and people are saying to pass the recordset containing the data I want to display. I have done this but if the database is not set correctly in the crystal report then no data is displayed. If I set the path in the report correctly it works.
There used to be a way to set the path of the database via VB code but I cant see that now.
I need the user to specify the path of the database when they load the database and I want to pass this info onto the crystal reports.
Im using the following code:
VB Code:
Private Sub DisplayPersonReport(Optional ByVal plgPersonID As Long = 0) 'Display the person report Dim pstPerson As String Dim prsPerson As New ADODB.Recordset Dim pcrCrystalReports As New CRAXDRT.Application Dim prpPerson As CRAXDRT.Report Dim pinResponse As Integer 'Check to see if report file exists If FileExists(mstReportPath & "\Person.rpt") = True Then Set prpPerson = pcrCrystalReports.OpenReport(mstReportPath & "\Person.rpt", 1) pstPerson = "SELECT * " & _ "FROM tblPerson " If plgPersonID <> 0 Then pstPerson = pstPerson & "WHERE PersonID = " & plgPersonID End If prsPerson.Open pstPerson, gcnLPFMS, adOpenStatic, adLockReadOnly, adCmdText If prsPerson.RecordCount = 0 Then pinResponse = MsgBox("There is no data to display in report.", vbExclamation + vbOKOnly, "No data") Unload frmReport Else crvReports.DisplayBorder = False crvReports.DisplayTabs = False crvReports.EnableDrillDown = False crvReports.EnableRefreshButton = False prpPerson.DiscardSavedData prpPerson.Database.SetDataSource prsPerson, 3, 1 crvReports.ReportSource = prpPerson crvReports.ViewReport End If prsPerson.Close Else pinResponse = MsgBox("The file " & mstReportPath & "\Person.rpt does not exist.", vbExclamation + vbOKOnly, "File Not Found") End If End Sub




Reply With Quote