how do I pass a query parameter from a form using visual basic?

  • Thread starter Thread starter TOMK
  • Start date Start date
T

TOMK

I have a form that has a lot of ORDER information combined from various
tables. I want to use a query to run a report that summarizes the ORDER. I
want to pass the ORDER# from the form to a report that is based on a query.
I don't want to use a parameter query that asks the user what ORDER to print.
I just want to take it directly from the form.

I know it's basic, but so are my programming skills.

Thanks
 
In the query you can refer to the text box in the form, as a criteria

Forms![FormName]![TextBoxName]

Or, use the Where condition of the OpenRport command line
Dim MyCondition As String
MyCondition = "[ORDER#]=" & Me.[MyCondition]
Docmd.OpenReport , , , MyCondition

If the ORDER# field type is string then use
MyCondition = "[ORDER#]='" & Me.[MyCondition] & "'"

Adding single quote before and after the value
 
The following standard solution may not be quite what you want, but it's one
way of doing it.

One standard solution is to use the report's open event to open the Order
form in dialog mode. Dialog mode will suspend the report's open event so the
report won't open until the Order form is made invisible. After the user has
selected the appropriate order, the Order form could have an 'OK' command
button that hides the form, at which point the report's open event will
continue. The report's record source can then be a query that uses the
Order number textbox on the Order form as a criterion to limit the records
opened in the report. To tidy things up, the report's Close event can close
the Order form. In other words, this whole process simply means the user
opens the report and everything else is taken care of. You may also want to
stop the report from opening if there is no data (ie no Order number
available) by using the report's NoData event.

Regards
Geoff
 
Back
Top