Finally got around to writing some code to view my crystal reports..

All is working well EXCEPT when I specify criteria on my form. Meaning I have a form with 4 combo boxes at the top. Users can select a customer followed by a site, followed by a commission, etc. But whenever I specify any criteria I get the following error when I try to open the report:

Login Failed For User SA
blah blah blah....
....


My code is as follows:

VB Code:
  1. Private Sub Form_Load()
  2. On Error GoTo Err_Handler
  3.  
  4. Dim strReportPath As String
  5.  
  6. Select Case (frmReports.SSTab1.Tab)
  7.     'project
  8.     Case 0:
  9.         If frmReports.optRptEnc3.Value = True Then
  10.             SetRptName ("rptEnclosure3.rpt")
  11.         End If
  12.        
  13.     'mgmt
  14.     Case 1:
  15.    
  16.     'misc
  17.     Case 2:
  18.    
  19.     'admin
  20.     Case 3:
  21.    
  22. End Select
  23.    
  24. strReportPath = App.Path & "\Reports\"
  25. Set objCrystalApp = New CRAXDRT.Application
  26. Set objReport = objCrystalApp.OpenReport(strReportPath & GetRptName, 0)
  27.  
  28. 'now check for criteria
  29.     If frmReports.cboRptQuoteNumbers.Text = "" Then
  30.         'no quote
  31.     Else
  32.         objReport.RecordSelectionFormula = "{Proposals.ProposalID} = " & frmReports.cboRptQuoteNumbers.ItemData(frmReports.cboRptQuoteNumbers.ListIndex)
  33.         GoTo LabelViewReport
  34.     End If
  35.    
  36.     If frmReports.cboRptCustomers.Text = "" Then
  37.         'no customer AND no quote...that means
  38.         'NO criteria has been selected..so we simply view
  39.         'the report
  40.         GoTo LabelViewReport
  41.     Else
  42.         objReport.RecordSelectionFormula = "{Proposals.CustomerID} = " & frmReports.cboRptCustomers.ItemData(frmReports.cboRptCustomers.ListIndex)
  43.     End If
  44.    
  45.     If frmReports.cboRptSites.Text = "" Then
  46.         'no customer AND no quote...that means
  47.         'NO criteria has been selected..so we simply view
  48.         'the report
  49.         GoTo LabelViewReport
  50.     Else
  51.         objReport.RecordSelectionFormula = "And {Proposals.SiteID} = " & frmReports.cboRptSites.ItemData(frmReports.cboRptSites.ListIndex)
  52.     End If
  53.    
  54.     If frmReports.cboRptComms.Text = "" Then
  55.         'no customer AND no quote...that means
  56.         'NO criteria has been selected..so we simply view
  57.         'the report
  58.         GoTo LabelViewReport
  59.     Else
  60.         objReport.RecordSelectionFormula = "And {Proposals.CommissionID} = " & frmReports.cboRptComms.ItemData(frmReports.cboRptComms.ListIndex)
  61.     End If
  62.    
  63. LabelViewReport:
  64. frmCRViewer.CRViewer91.ReportSource = objReport
  65. frmCRViewer.CRViewer91.ViewReport
  66.  
  67. Done:
  68. Set objReport = Nothing
  69. Set objCrystalApp = Nothing
  70. Exit Sub
  71.  
  72. Err_Handler:
  73. MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
  74. Resume Done
  75.  
  76. End Sub

First I check which tab the user is on to determin the report. For now I only have 1 report. Then I set the report name. Then I finally check for criteria and then open the report. It always works with no criteria but right when I have criteria it fails.

Jon