I am having a problem with my Crystal Report...but I'm not sure if it's my VB6 program or the CR. I have written code in VB to access my Crystal Report, however, whenever I run the program to access the report....the data is invalid. I know this because I check the Access Database to see what SHOULD be on the report. Should I be refreshing the report data everytime BEFORE I run the report and if so, how do I do this?

I have attached my VB code.

Thanks,

Blake

VB Code:
  1. Private Sub Form_Load()
  2.     Dim oApp        As CRAXDRT.Application
  3.     Dim oReport     As CRAXDRT.Report
  4.     Dim oRs         As ADODB.Recordset
  5.     Dim oConn       As New ADODB.Connection
  6.     Dim sSQL        As String
  7.     Dim dbPath      As String
  8.    
  9.     On Error GoTo ErrProc
  10.    
  11.     Load frmMessage
  12.     DoEvents
  13.     DoEvents
  14.     DoEvents
  15.    
  16.     Me.Width = MDIMain.ScaleWidth
  17.     Me.Height = MDIMain.ScaleHeight
  18.     Me.Left = 0
  19.     Me.Top = 0
  20.    
  21.     CR1.Height = Me.ScaleHeight - 400
  22.     CR1.Width = Me.ScaleWidth - 300
  23.    
  24.     dbPath = App.Path & "\JIC.mdb"
  25.    
  26.     oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";User Id=admin;Password=;"
  27.     oConn.Open
  28.    
  29.     Select Case report_type
  30.         Case "1"    'Master Item Listing Report
  31.             sSQL = "SELECT * FROM tblItemMaster"
  32.             Set oRs = New ADODB.Recordset
  33.             Set oRs = oConn.Execute(sSQL)
  34.             Set oApp = New CRAXDRT.Application
  35.             Set oReport = oApp.OpenReport(App.Path & "\Reports\ItemListing.rpt", 1)
  36.             oReport.Database.SetDataSource oRs, 3, 1
  37.             CR1.ReportSource = oReport
  38.             CR1.ViewReport
  39.         Case "2"    'Item Reorder Status Report
  40.             sSQL = "SELECT * FROM tblItemMaster"
  41.             Set oRs = New ADODB.Recordset
  42.             Set oRs = oConn.Execute(sSQL)
  43.             Set oApp = New CRAXDRT.Application
  44.             Set oReport = oApp.OpenReport(App.Path & "\Reports\ItemReorderStatus.rpt", 1)
  45.             oReport.Database.SetDataSource oRs, 3, 1
  46.             CR1.ReportSource = oReport
  47.             CR1.ViewReport
  48.         Case "3"    'Item Inventory Report
  49.             sSQL = "SELECT * FROM tblItemMaster"
  50.             Set oRs = New ADODB.Recordset
  51.             Set oRs = oConn.Execute(sSQL)
  52.             Set oApp = New CRAXDRT.Application
  53.             Set oReport = oApp.OpenReport(App.Path & "\Reports\ItemInventory.rpt", 1)
  54.             oReport.Database.SetDataSource oRs, 3, 1
  55.             CR1.ReportSource = oReport
  56.             CR1.ViewReport
  57.         Case "4"    'Item Inventory Alert Report
  58.             sSQL = "SELECT * FROM tblInventoryRpt"
  59.             Set oRs = New ADODB.Recordset
  60.             Set oRs = oConn.Execute(sSQL)
  61.             Set oApp = New CRAXDRT.Application
  62.             Set oReport = oApp.OpenReport(App.Path & "\Reports\ItemInventoryAlert.rpt", 1)
  63.             oReport.Database.SetDataSource oRs, 3, 1
  64.             CR1.ReportSource = oReport
  65.             CR1.ViewReport
  66.            
  67.             'Delete all records from the tblInventoryRpt table once report has printed
  68.             tblInventoryRpt.Index = "PrimaryKey"
  69.             tblInventoryRpt.Seek ">", ""
  70.            
  71.             If tblInventoryRpt.NoMatch Then
  72.             Else
  73.                 Do Until tblInventoryRpt.EOF
  74.                     tblInventoryRpt.Delete
  75.                     tblInventoryRpt.MoveNext
  76.                 Loop
  77.             End If
  78.         Case "5"    'Customer Listing Report
  79.             sSQL = "SELECT * FROM tblClients"
  80.             Set oRs = New ADODB.Recordset
  81.             Set oRs = oConn.Execute(sSQL)
  82.             Set oApp = New CRAXDRT.Application
  83.             Set oReport = oApp.OpenReport(App.Path & "\Reports\CustomerListing.rpt", 1)
  84.             oReport.Database.SetDataSource oRs, 3, 1
  85.             CR1.ReportSource = oReport
  86.             CR1.ViewReport
  87.         Case "6"    'Vendor Listing Report
  88.             sSQL = "SELECT * FROM tblVendor"
  89.             Set oRs = New ADODB.Recordset
  90.             Set oRs = oConn.Execute(sSQL)
  91.             Set oApp = New CRAXDRT.Application
  92.             Set oReport = oApp.OpenReport(App.Path & "\Reports\VendorListing.rpt", 1)
  93.             oReport.Database.SetDataSource oRs, 3, 1
  94.             CR1.ReportSource = oReport
  95.             CR1.ViewReport
  96.     End Select
  97.    
  98.     Unload frmMessage
  99.    
  100.     Exit Sub
  101.    
  102. ErrProc:
  103.     Select Case Err
  104.         Case 384
  105.             Resume Next
  106.         Case Else
  107.             MsgBox Err & ": " & Error
  108.     End Select
  109. End Sub