Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Access - Capture Query Parameter

Posted on 2016-10-11
2
Medium Priority
?
61 Views
Last Modified: 2016-10-11
I created a simple Access form with several buttons that basically runs a set of queries and allows the user to save the result to an excel file, with a set file name. Besides Access queries, it uses macros, and a few VBA RunCode functions to do some simple stuff. I don't want to over-complicate things, but now I find that it would be helpful if the saved excel file name could be created dynamically according to a certain format, with the format containing the date of the report. To do this efficiently, I need to capture the date of the report. This date is entered by the user when the first query is run, because there is a parameter in the query which causes the the query to stop and ask for a value. The parameter ([ReportMonth]) is used in the query's WHERE clause: WHERE (((ConvertMyStringToDate(SPS.submissionDt)) Between CDate(DatePart("m",[ReportMonth]) & "/23/" & DatePart("yyyy",[ReportMonth])) And CDate(DatePart("m",DateAdd("m",1,[ReportMonth])) & "/22/" & DatePart("yyyy",DateAdd("m",1,[ReportMonth]))))) Or IP.startDate=[ReportMonth].  I would like to capture this value (as a string) and use it later in the creation of the file name, which would look something like:  fileName = ABCD_YYYYMMDD.xlsx.

I suspect I could use an input box at the beginning - before the first query - to capture it, and maybe update a table with the value, but then how would I use it in the WHERE clause?  I would have no trouble creating the file name.
0
Comment
Question by:bassman592
2 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 41838588
<<I suspect I could use an input box at the beginning - before the first query - to capture it, and maybe update a table with the value, but then how would I use it in the WHERE clause?  I would have no trouble creating the file name.>>

  Just add a text control on it to capture the date.

 The query then can refer directly to the form control.  In the query designer, just add:

=Forms![<myformName>]![<myControlName>]

 on the criteria line, replace the < >'s with the correct values.

Jim.
0
 

Author Closing Comment

by:bassman592
ID: 41838850
Ok, thanks! I was hoping to not add any physical objects, just code, but that's probably the most straightforward solution.
0

Featured Post

Industry Leaders: 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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
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: …

916 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