Solved

run a query from a command button with criteria

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now