Auto-Generate File Name with Field Content...


Chris Smith

Hello all!

I have a DB with a query that I need to get the data out to excel while autogenerating the file name with a field. Initially, I wanted a date range if possible...

IE. NewGradList_01-01-08_to_11-01-08.xls

Previously, I was using a date stamp ->
="NewGradList_" & Format(Date(),"mmddyy") ; however now I need to use a range. These ranges will vary each time the report is ran by the 'end-user'. When the Parameters are entered ->

[Enter Start Day ~ Example mm/dd/yy] and [Enter End Day ~ Example mm/dd/yy] I was going to append those to the table and pull those dates into the File name, then once the Query is finished I was using a SendObject-Range only function to include all fields except for the date paramenters I just appended to the query.

Not sure if that all made any sense =) I know its a lot of loaded questions! Any assistance or insight would be most appreciated! I am willing to do it in SQL or VB... just not sure of the steps.

Thank you all!



Steve Schapel


I would advise against a Parameter Query (i.e. where the user is prompted to
enter the criteria). Instead, you should put 2 unbound textboxes on the
form from which the export macro is implemented, and have the user enter the
start and end dates of the date range in these boxes. Set the Format
property of the textboxes to any valid date format. Let's say the textboxes
are named StartDate and EndDate. Then you would do similar to what you have
="NewGradList_" & Format([StartDate],"mmddyy") & "_to_" &
Format([EndDate],"mmddyy") & ".xls"

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question