Results 1 to 8 of 8

Thread: Bruce, Techy...its that darn crystal ? again...

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Bruce, Techy...its that darn crystal ? again...

    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

  2. #2

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    EDITED CODE

    I had found I was using some wrong fields...

    But now Im getting an error when a second piece of criteria is selected it says:

    The remaining text does not appear to be part of the formula.


    It happens when again I select another criteria and it hits the And portion of the code:

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

    Jon

  3. #3
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Buddy ... just do me a little favour. I just sent you the APP i was talking about. Take it and run it and you will realize its not a good idea to embed your reports in the VB app. In the meantime i will look into this code of your.

  4. #4

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by techyspecy
    Buddy ... just do me a little favour. I just sent you the APP i was talking about. Take it and run it and you will realize its not a good idea to embed your reports in the VB app. In the meantime i will look into this code of your.
    Who said my reports were embedded?

    Jon

  5. #5

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    My reports are in there own directory totally seperate from the application itself. I have not imported or brought in any reports. I use the path to open them up.

    I dont think what you sent me is really what Im looking for..I would really just like to fix the code that keeps throwing up an error saying the string is not part of the formula???

    Thanks.. Jon

  6. #6

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    O think I know why now...duhh..I keep resetting the formula..and the AND kills it...

    Ill come back with a response in a bit...

    Jon

  7. #7

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Ok I got it working with this...

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


    BUT there still is a problem for a record that does not exist in the database...The report still opens up with no header information but it still shows the subreports information...even though its child records for a totally different parent. Meaning the criteria I selected on my form is not even a record in the db. Then I click ok to open the report and it opens it...at the top of the report is NO info (which is right)...but it shows all the subreports with DATA...from another record. Is there a way to pop up a message saying the report doesnt exist for your data and then the app wont open the report?

    Thanks,
    Jon
    Last edited by jhermiz; May 15th, 2003 at 08:50 AM.

  8. #8

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Anyone with ideas :-(

    Jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width