1

I have written a below mentioned code which export the Query into a Excel file.

 Public Function exportToXl11() Dim dbs As DAO.Database Set dbs = CurrentDb Dim sFilename As String sFilename = "c:\ExportFile\Output_Results.xlsx" DoCmd.OutputTo acOutputQuery, "metrics2", acFormatXLSX, sFilename, Autostart:=False End Function 

I have another table name "Date1" which have date. I want a code which will export the query with a date given in a "Date1" table. Like the output will be "Output_results_23-05-2020.xlsx" instead of "Output_Results.xlsx"

1 Answer 1

1

You can include the date in the filename variable:

sFilename = "c:\ExportFile\Output_Results_" & Format$(Now, "yyyymmdd") & ".xlsx" 

You can format it any way you want, but make sure you do not include characters that are not allowed in filenames.

Sign up to request clarification or add additional context in comments.

4 Comments

It should take date from the "Date1" table instead of Now
OK, then change it. You did not provide any information about that table, so I cannot give you specific code for it. Your question seems to actually be about how to get a date variable out of a table.
You didnt change anything that I can see, and you did not provide any information about the table in question. But it seems you are now changing the question. Is the real question "how do i get a value from a table?" Because my answer shows you how to add anything you want to the filename variable.
There is a Table called "Date1" which store Date like Date1.date='2020-05-31". The output of the file will be "Output_results_2020-05-31"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.