[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Passing parameter from VB to Crystal Reports

Hi Experts-

I have a variable as a 'Single' datatype in my VB program.  I'm trying to pass it as a parameter to my Crystal Report.  The parameter has been set up as a 'Number' datatype in Crystal.  I get a type mismatch error when the program tries to pass the variable to the report parameter.  Crystal only has Currency and Number numeric datatype choices.  What do I have to do to get these two datatypes to match up?  

Looking forward to your responses!
0
MariaHalt
Asked:
MariaHalt
  • 7
  • 3
  • 2
  • +1
1 Solution
 
ebolekCommented:
why dont you convert the single to integer and then send it to Crystal in VB.
0
 
MariaHaltAuthor Commented:
I'm using the Single datatype because there's decimal involved.
0
 
ebolekCommented:
create a forumulain the report and convert the single variable to currency

currencyvar var :=$({databasefield});
var
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
MariaHaltAuthor Commented:
The problem is that the report will not accept the single variable at all, not as a number or currency parameter.  

If I convert the single variable to a string in VB and change the parameter datatype in the report to string, it accepts it, string to string.  The problems with this is 1.) Formatting (for some reason numbers in Crystal do not right align the same as strings) and 2.) Have to create a new Crystal Formula field, converting the string parameter to number and 3.) Update my formuals to use the new field instead of the parameter I've already established.  

There must be a simple way to pass a numeric value to Crystal.  
0
 
mlmccCommented:
What language?  What version of Crystal?

mlmcc
0
 
MariaHaltAuthor Commented:
VB6 and Crystal 8.5
0
 
MariaHaltAuthor Commented:
I'm increasing the point value to get more responses.
0
 
ebolekCommented:
did you try to convert it to currency usinf this formula:
create a forumulain the report and convert the single variable to currency

currencyvar var :=$({databasefield});
var
0
 
MariaHaltAuthor Commented:
I'm passing a parameter, not a database field.  

The Crystal report will not accept the Single datatype variable.  I changed the parameter to currency and am getting the same error, type mismatch.  Let me rephrase my original question, How does one pass a numeric variable to a Crystal report parameter of type number or currency?
0
 
vidruCommented:
What means are you using to access the Crystal Print Engine: API, RDC, OCX, other?  And can you post the code you're trying?

-dave
0
 
MariaHaltAuthor Commented:
Short version of VB code...

Private Sub cmdGenerateReports_Click()
Dim sinGFCredits As Single
Dim sinGPCredits As Single

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code assigning sinGFCredits & sinGPCredits, then...
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set crApplication = CreateObject("CrystalRuntime.application")
Set crReport = crApplication.OpenReport(strReportName)
crReport.Database.SetDataSource rstDb, 3, 1
Set crParameters = crReport.ParameterFields
 'Loop through the parameters fields in the report by name and pass variable
For Each crParameter In crParameters
      Select Case crParameter.ParameterFieldName
            Case "GFCredits"
                 crParameter.SetCurrentValue sinGFCredits
            Case "GPCredits"
                 crParameter.SetCurrentValue sinGPCredits
      End Select
 Next crParameter

I use this same bit of code for passing strings to string type parameters in Crystal with no problem.  Don't know why numbers are problematic.  TIA
0
 
vidruCommented:
Apparently, Crystal doesn't like Singles, but this should work for you:

For Each crParameter In crParameters
      Select Case crParameter.ParameterFieldName
            Case "GFCredits"
                 crParameter.SetCurrentValue Val(sinGFCredits)
            Case "GPCredits"
                 crParameter.SetCurrentValue Val(sinGPCredits)
      End Select
 Next crParameter

-dave
0
 
MariaHaltAuthor Commented:
It worked!  Thank you!!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now