Run Parameterized Query in VB?

  • Thread starter Thread starter Meilu
  • Start date Start date
M

Meilu

Hello,
I have a Query Bobo that has a parameter of [OrderID].

I have an unbound form with 3 fields:
OrderID
Begining_Date
Ending_Date

The form also has a button called: "generate report"

After clicking the button I want to be able to run Query
Bobo... Any idea how to do that?

Thanks in advance!
Mercy
 
Queries are not really intended for viewing data. Rather, they are for
selecting, ordering and collating data.

A better way to achieve what you want is to create a report based on your
query. Then specify selection criteria in your query based on the values in
your form.

In the criteria row, for your OrderID field, put:
=Forms![Your Form Name]![OrderID]

and under the date field, put:
Between Forms![Your Form Name]![Beginning_Date] and Forms![Your Form
Name]![EndingDate]

Then, your command button just needs to open the report:
DoCmd.OpenReport "Your Report Name", acViewPreview

An even better way is to specify the selection filter as you open the
report:

Dim sFilter as String
sFilter = "[OrderID]=" & Me!OrderID _
& " and [DateField] between " _
& Format(Me!Beginning_Date, "\#mm\dd\yyyy\#") _
& " and " & Format(Me!Ending_Date, "\#mm\dd\yyyy\#")
DoCmd.OpenReport "Your Report Name", acViewPreview, , sFilter
 
Back
Top