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:
  1. Private Sub DisplayPersonReport(Optional ByVal plgPersonID As Long = 0)
  2.    
  3.     'Display the person report
  4.     Dim pstPerson As String
  5.     Dim prsPerson As New ADODB.Recordset
  6.     Dim pcrCrystalReports As New CRAXDRT.Application
  7.     Dim prpPerson As CRAXDRT.Report
  8.     Dim pinResponse As Integer
  9.        
  10.     'Check to see if report file exists
  11.     If FileExists(mstReportPath & "\Person.rpt") = True Then
  12.         Set prpPerson = pcrCrystalReports.OpenReport(mstReportPath & "\Person.rpt", 1)
  13.         pstPerson = "SELECT * " & _
  14.                     "FROM tblPerson "
  15.         If plgPersonID <> 0 Then
  16.             pstPerson = pstPerson & "WHERE PersonID = " & plgPersonID
  17.         End If
  18.                    
  19.         prsPerson.Open pstPerson, gcnLPFMS, adOpenStatic, adLockReadOnly, adCmdText
  20.         If prsPerson.RecordCount = 0 Then
  21.             pinResponse = MsgBox("There is no data to display in report.", vbExclamation + vbOKOnly, "No data")
  22.             Unload frmReport
  23.         Else
  24.             crvReports.DisplayBorder = False
  25.             crvReports.DisplayTabs = False
  26.             crvReports.EnableDrillDown = False
  27.             crvReports.EnableRefreshButton = False
  28.             prpPerson.DiscardSavedData
  29.             prpPerson.Database.SetDataSource prsPerson, 3, 1
  30.             crvReports.ReportSource = prpPerson
  31.             crvReports.ViewReport
  32.         End If
  33.         prsPerson.Close
  34.     Else
  35.         pinResponse = MsgBox("The file " & mstReportPath & "\Person.rpt does not exist.", vbExclamation + vbOKOnly, "File Not Found")
  36.     End If
  37.    
  38. End Sub