Run Parameterized Query in VB?

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
 
G

Graham Mandeno

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top