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.