Solved

run a query from a command button with criteria

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

747 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

16 Experts available now in Live!

Get 1:1 Help Now