Solved

MS Access - Capture Query Parameter

Posted on 2016-10-11
2
43 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 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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