Martin
Martin

Reputation: 1213

Set Crystal Reports ParameterField to NULL at runtime

I have a Crystal Reports 8.5 report that uses a Stored Procedure as a data source. This Stored Procedure has a couple of parameters of which some are optional and require to be Null when executing the procedure.

In VB6 I tried to clear the parameter but then Crystal Reports prompts the user to enter a value. Then I tried setting it to Nothing but that gives an Invalid Type error. See the code below for an example of the ParameterField part.

Dim crApp As CRAXDRT.Application
Dim crRep As CRAXDRT.Report

Set crApp = New CRAXDRT.Application
Set crRep = crApp.OpenReport(ReportFile, 1)

'Option 1
crRep.ParameterFields(1).ClearCurrentValueAndRange '<-- This won't set it to Null but it clears the current value. User gets a prompt to enter a value.

'Option 2
crRep.ParameterFields(1).ClearCurrentValueAndRange
crRep.ParameterFields(1).AddCurrentValue Nothing '<-- Setting it to nothing gives an error at runtime

So how to set a parameter to Null at runtime?

Upvotes: 2

Views: 371

Answers (1)

Martin
Martin

Reputation: 1213

You have to set the parameterfield to Empty.

crRep.ParameterFields(1).ClearCurrentValueAndRange
crRep.ParameterFields(1).AddCurrentValue Empty

This will set it to Null when executing the Stored Procedure. Sometimes you even have to set it to Empty while the current value already is Empty. Because when you Print the report it still could prompt the user for input.

Upvotes: 4

Related Questions