Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

Problems running Crystal Report from VB.Net when Parameters / Record Selection not set programmatically

I have a VB.Net application that allows users to browse, select, edit and run Crystal Reports.  The program design is very simple: when the Run option is selected, the program does not dynamically set the RecordSelectionFormula neither does it set any Parameter values.  Instead, the users simply key in the Parameter values in the pop up displayed by the Crystal Report Viewer and rely on the record selection formula that is already set in the Crystal Report.

The problem is that, when the report is run using the attached code the Parameters window is not displayed and so the users are not able to set the parameter values.  If, however, I uncomment out the oDoc.Refresh line, then the parameter window is displayed but the reports RecordSelection formula does not work.

This should be easy but it is giving me a lot of grief!



Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table = Nothing
Dim crConnInfo As New ConnectionInfo
Dim crLogonInfo As TableLogOnInfo
 
oDoc = New ReportDocument
oDoc.Load(_ReportFilePath)
crDatabase = oDoc.Database
crTables = crDatabase.Tables
 
 'set connection info  ---------------------------------------------------------
 For Each crTable In crTables
       With crConnInfo
               .ServerName = gServer
               .DatabaseName = gDatabase
               .UserID = gUserName
               .Password = gUserPassword
       End With
       crLogonInfo = crTable.LogOnInfo
       crLogonInfo.ConnectionInfo = crConnInfo
       crTable.ApplyLogOnInfo(crLogonInfo)
       crTable.Location = gEnterpriseMRM_Database & ".dbo." & _
       crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next '------------------------------------------------------------------------
 
 crViewer.ReportSource = Nothing
 
     ' when commented out Parameters window not displayed
     ' when left in, Parameters window is displayed but ReportSelectionFormula does not work
    'oDoc.Refresh()              
 
crViewer.ReportSource = oDoc

Open in new window

0
ccravenbartle
Asked:
ccravenbartle
  • 4
  • 4
1 Solution
 
mlmccCommented:
What version of Crystal?

Is the report saved with data?

mlmcc
0
 
ccravenbartleAuthor Commented:
Crystal Reports XI Release 2

If I have the [Save Data with Report] setting ticked in the Crystal Report then the Parameters window does not open unless I manually click the Refresh button in the viewer or uncomment out the oDoc.Refresh.

If I do not have the [Save Data with Report] ticked then the Parameters window does display.

In neither case does it appear to evaluate the Record Selection Formula
{PubManuscript.PaperAccepted}=true
so it prints all Manuscripts not just the ones which have been Accepted.
If I do a msgbox (odoc.RecordSelectionFormula) immediately before the
crViewer.ReportSource = oDoc line
then it shows
( {PubManuscript.PaperAccepted} )
0
 
mlmccCommented:
Can the field be NULL?

If so you need to test for it.  Crystal returns an unknown value when it evaluates a NULL value.  In my experience in the record selectioin it returns TRUE

Try
Not(IsNull({PubManuscript.PaperAccepted})) and ({PubManuscript.PaperAccepted}= TRUE)

mlmcc
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ccravenbartleAuthor Commented:
The field can be null and I modified the report accordingly but it still failed.
However, I have now discovered the root of the problem - it is to do with the Group Selection and Record Selection formulas.  I do not understand what is happening though.

The Report has been written to use this Group Selection Formula
{PubManuscript.PublicationType} = {?Publication type} AND
{PubManuscript.PublicationVolume} = {?Volume} AND
{PubManuscript.PublicationIssue} = {?Issue}
and this Record Selection Formula
({PubManuscript.PaperAccepted}= TRUE)

Scenario 1 - Using Group and Record Selection as above
Run from Crystal Reports Designer - works OK
Run from VB Application - Group Selection is evaluated but not Record Selection

Scenario 2- Using Record Selection only (i.e. place all 4 formula elements within Record Selection)
Run from Crystal Reports Designer - works OK
Run from VB Application -  Neither the Group Selection or the Record Selection is evaluated - all records are returned.

Scenario 3- Using Group Selection only (i.e. place all 4 formula elements within Group Selection)
Run from Crystal Reports Designer - works OK
Run from VB Application -  works OK

Any ideas?


0
 
mlmccCommented:
Can any of those fields be NULL?

mlmcc
0
 
ccravenbartleAuthor Commented:
Yes: {PubManuscript.PublicationType} ,{PubManuscript.PublicationVolume}  and PubManuscript.PublicationIssue}  can all be NULL
0
 
mlmccCommented:
You need to test for NULL.  What do you want to happen if a field is NULL?

Use IsNull

Something like this
(Not IsNull({PubManuscript.PublicationType} ) AND {PubManuscript.PublicationType} = {?Publication type})
AND
(Not IsNull({PubManuscript.PublicationVolume}) AND {PubManuscript.PublicationVolume} = {?Volume})
 AND
(Not IsNull({PubManuscript.PublicationIssue}) AND {PubManuscript.PublicationIssue} = {?Issue} )
({PubManuscript.PaperAccepted}= TRUE)

mlmcc
0
 
ccravenbartleAuthor Commented:
Thank you for your persistence.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now