Skip to Content
author's profile photo Former Member
Former Member

VB code for CR identical in two procedures but only one works

I am trying to convert an application built by someone that has left our organization. The app was written in VB in VS2002. This is one of several that I am converting; others have gone fine. The reason we are converting the apps is because the server they are on is dying and we need to move them to a more consolidated share structure on a new server. The problem that I have run into is in a part of her code that runs a Crystal Report that has two different parts, Part1 and Part2 (as I'll refer to them). The .NET front-end is connected to an Access db backend with her customized queries inside also.

The report works fine in the VS2002 version of the program and the second half of the report (Part2) runs fine in my VS2005 converted program. The code in the two procedures is basically identical except for the report queries they run. (I have even tried swapping the queries out in the code and it stills gives me the same error) In debug mode, the line it fails on has the exact same result in it also for both procedures. The two procedures even pick up the same same queried value for their variables, which get populated in both successfully, but it just fails at the very end, right when it is supposed to print the first report page, with the following error:

CrystalDecisions.CrystalReports.Engine.FormulaException was caught Message="
Error in File C:\DOCUME~1\akomarek\LOCALS~1\Temp\temp_5b508b45-188e-45e9-81e6-939521728ba1 {E33AF2AD-BB1F-4270-BCDE-6ED2D8B9EEFB}.rpt:


SQL Expression error: Error in compiling SQL Expression : SQL Expressions can not be used in this report..." Source="CrystalDecisions.ReportAppServer.DataSetConversion"
StackTrace: at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN) at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN) at PayReqProject.frmPayReqRpt.BindFirstReport() in C:\PROJECTS\Payroll\PayReqProject\frmPayReqRpt.vb:line 101


The offending line 101 is: oRpt.PrintToPrinter(1, False, 0, 0)

Here is the code from Part1:

Private Sub BindFirstReport() 
Dim strOleDB As String Dim cnOleDB As New OleDbConnection(m_strConnectionString) Dim dsOleDB As New DataSet() Dim oRpt As New rptPaymentRequest() Dim daOleDB As New OleDbDataAdapter(strOleDB, cnOleDB)
Try ' Build Select statement to query invoices from tblInvoices
strOleDB = "SELECT * FROM qryFindPayReqsForBatchNbr WHERE BatchNbr = " & m_intBatchNbr & ";" daOleDB.Fill(dsOleDB, "qryFindPayReqsForBatchNbr")
'Uncomment the following line to write out what is being returned so you can compare it to what you you are getting if you have errors 'dsOleDB.WriteXmlSchema("c:\payreq_schema_test.xml") oRpt.SetDataSource(dsOleDB) 'This code allows the report to go directly to the printer without previewing
oRpt.RecordSelectionFormula = " {qryFindPayReqsForBatchNbr.BatchNbr} = " & CStr(m_intBatchNbr) & " " oRpt.PrintToPrinter(1, False, 0, 0) *************FAILS ON THIS LINE************** ''This code would allow you to preview the report with the viewer before printing 'CrystalReportViewer1.ReportSource = oRpt 'CrystalReportViewer1.SelectionFormula = " {qryFindPayReqsForBatchNbr.BatchNbr} = " & CStr(m_intBatchNbr) & " " 'CrystalReportViewer1.RefreshReport() 'CrystalReportViewer1.DisplayGroupTree = False
Catch e As OleDbException MsgBox(e.Message, MsgBoxStyle.Critical, "OleDB Error") Catch e As Exception MsgBox(e.Message, MsgBoxStyle.Critical, "General Error") End Try End Sub


I tried the report preview code (with the print commented out) and got the same error message.

I have been working to resolve this for many hours and am at a loss; any light anyone can shine on this for me would be greatly appreciated.

Thanks in advance,

Al

Message was edited by: Ludek Uher

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on May 22, 2013 at 04:55 PM

    Hello Al

    As a test, I'd like you to comment out the record selection line:

    oRpt.RecordSelectionFormula = " {qryFindPayReqsForBatchNbr.BatchNbr} = " & CStr(m_intBatchNbr) & " "

    Theoretically, if you are using datasets, using a selecton on top is kind of loked down on as the selection should be part of the dataset creation. E.g.; upi're only adding overhead by having CR select data from a dataset which in effect is already selected data.

    Another thing to try is run the report in the CR Designer as detailed in this blog. If the report does not work in the designer, see this forum thread:

    http://scn.sap.com/thread/0001822727

    - Ludek

    Senior Support Engineer AGS Primary Support, Global Support Center Canada

    Follow us on Twitter

    Got Enhancement ideas? Try the SAP Idea Place

    Share Your Knowledge in SCN Topic Spaces

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.