PDA

View Full Version : FORM PARAMETERS IN A REPORT?! HELP!!!



sreyes17
07-10-2008, 01:09 PM
I have a query set up with parameters. I have created a report that runs off that query. So before I am able to view my report, I must enter the Parameter Values for the CLIENT, START DATE, and END DATE. This leads to 3 different pop-up boxes.

How do I create a form that would have all this information in one pop up box? That would run the report with the data I have selected in the client, start date, and end date fields?

CreganTur
07-10-2008, 01:56 PM
Parameters are just a part of the WHERE condition of a SQL statement. Also, if you look at the parameters for the DoCmd.OpenReport method, you'll see: expression.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs).

That WhereCondition is what you're going to want to deal with to enter parameters into your report via a Form.

On your form you'll need 3 text boxes (unbound). For sake of this example we'll name them txtClient, txtStart, txtEnd. You'll also need a button to launch the code to open your report with the parameters entered into the text boxes.

Here's an example of what your code could look like (this would be part of the OnClick event for the button):

Dim strClient As String
Dim StartDate
Dim EndDate

strClient = Me.txtClient
StartDate = CDate(Me.txtStart) '<<<Ensures that StartDate is of DataType Date
EndDate = CDate(Me.txtEnd) '<<<Ensures that EndDate is of DataType Date

DoCmd.OpenReport "ReportName", acViewPreview, _
, "CLIENT = '" & strClient & "'" & "And [Start Date] = #" & StartDate & "#" & "And [End Date] = #" & EndDate & "#

I might be a little off on the WHERE section - don't have time to test it right now, but this will at least point you in the right direction.

FYI: if you get an answer to a post that solves your problem, please mark your thread as solved (Click on Thread Tools, Mark As Solved)- Thanks :thumb