Solved

run a query from a command button with criteria

Posted on 2011-02-16
5
272 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 7 35
Documents and settings folder 30 78
Reference Controls on subforms 7 28
Trying to force an answer in a combobox 7 18
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 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