Link to home
Create AccountLog in
Avatar of hawb
hawb

asked on

Passing VB.NET variable to Crystal Report

I have a vb.net form in VS 2008.  The form contains a combobox listing locations, two textboxes to specify a date range, a ReportViewer control and a button to run the report based on the criteria inputted.  All I want to do is pass the location and date range criteria to the Report Header on my Crystal Report!  This seems like it should be very easy but I cant get it to work.

I tried inserting 2 formula fields into my report.  According to the Crystal Reports website it should be as easy as .....

rpt.FormulaFields.item(1).text = "MyLocation

But I dont even get a "FormulaFields" option via Intellisense in VB.NET?  Can someone let me know how to do this correctly?

Thanks!!
Mike


 
Avatar of Vaxman2
Vaxman2

This code is used with VS2005 and Crystal Reports XI R2.

On your Crystal Report make a parameter field called ReportHeader1, and place it on you report.

Then in the code to load the report:

Dim cr As New TestReport
cr.SetParameterValue("ReportHeader1", "This is a test header!")

Load the report as usual after that..

Avatar of hawb

ASKER

Thanks for the comment. I'm wondering if my issues revolve around the fact that I am displaying my report via the Crystal Report Viewer control?   This is what I did.

1.) I put a paramenter field called ReportHeader1 on my Report (called rptMain)
2.) On my form I have a Crystal Report Viewer Control whose report source = rptMain.
3.) On the Run Report button click event I put

Private Sub RunReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunReport.Click

rptMain.SetParameterValue("ReportHeader", "This is a test header")

rptViewer.Refresh
rptViewer.RefresReport

End Sub

These are the problems I am running into.

I keep getting the Crystal Reports 'Enter Parameter Values' prompt.  If I type something in it succesfully adds it to my report.  However, I dont want this prompt, I would like to pass the value based on the contents of the fields on my form.  In order to view the value I passed the parameter I need to refresh the report.  Everytime I refresh it, I get the prompt which overwrites my values?   Do you know how I can bypass this prompt?

Thanks!!
ASKER CERTIFIED SOLUTION
Avatar of hawb
hawb

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account