Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output file with Current Date as filename?

Status
Not open for further replies.

unvme

IS-IT--Management
Jan 20, 2003
29
US
I'm trying to output a report to a server so that users can view all of the reports from the past week. I'm using a macro to output the file, and I'm using a batch file to run the macro every evening. Any suggestions on how I would be able to save a report for each day of the week, with the current date in the filename?

Ex:
Report 03-03-03.xls
Report 03-04-03.xls
Report 03-05-03.xls
Report 03-06-03.xls
Report 03-07-03.xls


Thanks,
Ryan
 
Here's some code I use to do the same thing (Access 97):


Dim DriveName As String
Dim oldname As String
dim today as string
Dim rptname as string

rptname="Your Report Name"
Today=format(Now(),"short Date")

DriveName = "C:\Files\"
Oldname = "Test.txt"

newname = today + sp + oldname

testname = DriveName + newname
DoCmd.OutputTo acOutputReport,rptname,acFormatRTF,testname
end sub


I had to change a couple of things to have it make sense, but I think it will work (I'm in the middle of something and can't take the time to test it).


 
Sorry, didn't pay attention to the format......

My code creates a file in .rtf format, and the date is in front of the rest of the name.

 
Where would I place this code so that I would be able to have it run daily? Right now I have a batch file that executes a macro each evening. Thanks.
 
You can create a funtion and call the function with the "RunCode" command in your macro.

Or, you can paste the code into the "On Open" event of a blank form. Then, just have your macro open the form. After the code runs, you can have it close the form (Just add "docmd.close" on the line before "exit sub").

You can also put the code into the timer event on a form, have it check for the time of day, then run the code when a predetermined time is reached.

I'm sure there's a number of other ways to accomplish the same feat.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top