|
-
Mar 18th, 2010, 02:40 PM
#1
Thread Starter
Lively Member
[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.
-
Mar 18th, 2010, 02:55 PM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 19th, 2010, 04:13 AM
#3
Thread Starter
Lively Member
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
-
Mar 19th, 2010, 04:51 AM
#4
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"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 19th, 2010, 12:30 PM
#5
Thread Starter
Lively Member
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
-
Mar 19th, 2010, 03:25 PM
#6
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 19th, 2010, 09:37 PM
#7
Thread Starter
Lively Member
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.
-
Mar 20th, 2010, 02:45 AM
#8
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 20th, 2010, 07:54 AM
#9
Thread Starter
Lively Member
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
-
Mar 20th, 2010, 03:46 PM
#10
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"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 20th, 2010, 04:44 PM
#11
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|