?
Solved

run a query from a command button with criteria

Posted on 2011-02-16
5
Medium Priority
?
307 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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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