Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access - Capture Query Parameter

Posted on 2016-10-11
2
Medium Priority
?
55 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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