[RESOLVED] VBA Save Access Report As SNP File Name With Current Date
Hi, i am using the following code in Access to store a report as a snapshot file, which works perfectly.
Code:
Dim stDocName As String
stDocName = "My Report"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\MyReport.snp"
I would like to save the current date within the snp files name, or for a new folder to be created within the ReportFolder with the current date as its name.
Thanks For The Help In Advance.
Re: VBA Save Access Report As SNP File Name With Current Date
vb Code:
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\MyReport" & format(date, "yy-mm-dd") & ".snp"
change the format to suit
Re: VBA Save Access Report As SNP File Name With Current Date
Hi, thanks that works great.
Is there any way that i could get a new folder to be created, with the current date as its folder name, and the snapshot files to be saved in that folder.
Many Thanks
Re: VBA Save Access Report As SNP File Name With Current Date
vb Code:
mystr = format(date, "yy-mm-dd")
mkdir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr & "\MyReport.snp"
Re: VBA Save Access Report As SNP File Name With Current Date
Hi, i got that working thanks.
I just wanted to ask what is the purpose of mkdir in that code.
Also, i want to save all the reports in my database into the same folder, what is the simplest way of doing this. i can add
Code:
stDocName = "My Report New"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\MyReportNew.snp"
for each report, but was wondering if there is an easier way of doing this.
Also, i ran your code, and it worked perfectly, but the second time i run it, i get a Path File Error, possibly as a folder with the current date has already been created. Can i add the time to the folder name, which will allow me to run the code many times in a day.
Sorry for so many questions.
Thanks
Re: VBA Save Access Report As SNP File Name With Current Date
mkdir is make directory
you can test if the dirrectory already exists, using dir
vb Code:
if len(dir("C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr))=0 then mkdir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
Quote:
Also, i want to save all the reports in my database into the same folder, what is the simplest way of doing this.
do not create new folders if you want to save all the same folder
yes you can add time, but do you really need that many new folders? maybe better to have on folder for day, put time in filenames
vb Code:
mystr = format(now, "yy-mm-dd hhnn")
change format to suit, beware of invalid characters in filename / or : may be illegal characters
Re: VBA Save Access Report As SNP File Name With Current Date
Hi, as you suggested I am using the following code to store, reports in one folder for each day, with the time on the Report file names
Code:
Dim stDocName As String
mystr = Format(Date, "dddd-mmmm-yyyy")
MkDir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
stDocName = "My Report"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr & "\MyReport " & Format(Now, "(hh-nn AMPM)") & ".snp"
this code works perfectly, however if i run it again, i get a file path error.
I tried using, the
Code:
if len(dir("C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr))=0 then mkdir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
, but couldnt get that to work.
Thanks.
Re: VBA Save Access Report As SNP File Name With Current Date
oops, my appology, must add to look for directory and files
vb Code:
if len(dir("C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr, vbdirectory))=0 then mkdir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
Re: VBA Save Access Report As SNP File Name With Current Date
Hi, thanks that works great.
My code now is
Code:
Dim stDocName As String
mystr = Format(Date, "dddd-mmmm-yyyy")
if len(dir("C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr, vbdirectory))=0 then mkdir "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr
stDocName = "My Report"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr & "\MyReport " & Format(Now, "(hh-nn AMPM)") & ".snp"
One final thing, i want to save many reports into the same folder, for example Report 1, Report 2 etc.
Do i need to add
Code:
stDocName = "My Report 1"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr & "\MyReport1 " & Format(Now, "(hh-nn AMPM)") & ".snp"
to the code for each report, or is there an easier way of doing this.
Thanks
Re: VBA Save Access Report As SNP File Name With Current Date
vb Code:
stDocName = "My Report 1"
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)", "C:\Documents and Settings\khadafi\My Documents\ReportFolder\" & mystr & "\" & strDocName & Format(Now, "(hh-nn AMPM)") & ".snp"
Re: VBA Save Access Report As SNP File Name With Current Date
Hi, i couldn't get that last bit to work, but thanks. I have just added each report the way i suggested in my previous post.
Thank you for all your help.
Regards