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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosave File With Today's Date 1

Status
Not open for further replies.

misssaraliz

Technical User
Feb 14, 2002
12
0
0
US
I already have a macro set up that will automatically export a report and save it in Excel. My problem is in trying to save the file with the date the export was run (mmddyy) listed in the filename. Here is an example of what my filename needs to look like (using today 2/20/02 as an example):

c:\my documents\Legislation 022002.xls

The following syntax works fine in VB:

"C:\My Documents\Legislation " & Month(Date) & Day(Date) & Year(Date) & ".xls"

But this same syntax doesn't work with the macro object in Access.

Any ideas???
 
Drop this Function into a module and call the function from your existing macro or instead of the macro.

Function OutputFile()
On Error GoTo OutputFile_Err
Dim MyFile As String
' Don't forget to change folder location next line
MyFile = "C:\Folder Location\" & Format(Date, "mmddyy") & ".xls"

DoCmd.OutputTo acTable, "Department", "MicrosoftExcel(*.xls)", MyFile, False, ""


OutputFile_Exit:
Exit Function

OutputFile_Err:
MsgBox Error$
Resume OutputFile_Exit

End Function

Good Luck

Phil Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top