How can I imbed current date into outputto file name?

W

WildlyHarry

I am trying to imbed the current date into the file name of a report that I
am saving using the the docmd.outputto method. Below is the code that I am
using. How can I accomplish this? Thanks in advance for your help.

Dim MyDate As Date

stdocname4 = "rpt by market"

DoCmd.OutputTo acOutputReport, stdocname4, acFormatSNP, "By Market as of" &
MyDate & ".snp", True
 
D

Dennis

You do not need a variable called MyDate, just use 'Date' and this will
return todays date
e.g.
stdocname4 = "rpt by market"
DoCmd.OutputTo acOutputReport, stdocname4, acFormatSNP, "By Market as of " &
Date & ".snp", True
 
W

WildlyHarry

Thank you for the quick response. Your suggestion is the first that method
that I tried, and it did not work. When the report out puts it ignores the
"date" statement and produces a report titled "By Market as of.snp". Any
other thoughts?
 
D

Dennis

I've just realised that a filename cannot contain the '/' symbol so you will
need to set the date into a text field and then replace the / with a dash and
then assign the new text string to your filename instead.
 
W

WildlyHarry

That was the answer. Thanks

Dennis said:
I've just realised that a filename cannot contain the '/' symbol so you will
need to set the date into a text field and then replace the / with a dash and
then assign the new text string to your filename instead.
 

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

Top