Open a report with parameter

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

I got a report link to a query:
SELECT * FROM Employee
WHERE EmployeeNum = [Num]

How do I open this report from a form using Visual Basic and pass the
parameter into it?
 
Hi

Will you be opening the report from a command button on a form with
the value on the form? If so then try:
WHERE EmployeeNum = Forms![YourFormName]![Num]

Regards
 
I got a report link to a query:
SELECT * FROM Employee
WHERE EmployeeNum = [Num]

How do I open this report from a form using Visual Basic and pass the
parameter into it?

Do it the other way around. Open the form from the Report.

Create an unbound form.
Add a combo box.
Set the Row Source of the combo box to include the
EmployeeID field and the EmployeeName.
Name the Combo Box 'FindEmployee'.
Set it's Bound column to 1.
Set it's Column Count property to 2.
Set the Column Width property to 0";1"

Add a Command Button to the form.
Code the button's click event:

Me.Visible = False

Name this form 'ParamForm'.


In the Report's Record Source (the Query) [EmployeeNum] field criteria
line write:
forms!ParamForm!FindEmployee

Next, code the report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog

Code the report's Close event:
DoCmd.Close acForm, "ParamForm"

When ready to run the report, open the report.
The form will open and wait for the selection of the Employee wanted.
Click the command button and then report will run.
When the report closes, it will close the form.
 
Back
Top