?
Solved

run a query from a command button with criteria

Posted on 2011-02-16
5
Medium Priority
?
299 Views
Last Modified: 2012-05-11
I have a query I would like to run from a command button.  I would like to include the criteria for the date_run field.

In English it would look like this:

Run qryGlassing_Schedule where date_run = #2/16/2011#.

Thanks,
Brooks
0
Comment
Question by:gbnorton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75
ID: 34910980
So say your SQL for qryGlassing_Schedule is:

SELECT Table1.*
FROM Table1
WHERE (((Table1.date_run)=[Enter Run Date:]));

Private Sub btnOpenQry_Click()

DoCmd.OpenQuery "qryGlassing_Schedule ",acViewNormal

End Sub

You will get a prompt to enter the date.  Is this what you mean?

mx
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34911005
If the Date is somewhere on the form, or is today's date then in the criteria field of the query - right mouse click  - build and point the where you want to get the date field from.

If you want to click the button and have the program prompt for the info then just use the [enter date] in the criteria field of the query
0
 
LVL 44

Accepted Solution

by:
GRayL earned 2000 total points
ID: 34911056
I imagine you would have a text box named txtDateRun on your form named frmGlassing_Schedule along side the command button cmdRunQry.
I imagine the query has a WHERE clause so you need to add this:

AND Run_Date = Forms!frmGlassing_Schedule!txtDateRun

You enter your date in the text box and in the Click event of cmdRunQry enter this code:

Private Sub cmdRunQry()
  DoCmd.OpenQuery "qryGlassing_Schedule"
End Sub
0
 

Author Closing Comment

by:gbnorton
ID: 34916521
Perfect!
Thanks again.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 34919759
Thanks, glad to help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question