Access 2007 export to text file

qbjgqbjg
qbjgqbjg used Ask the Experts™
on
I have my export working. I used this code in a button:

Private Sub Command18_Click()

DoCmd.TransferText acExportDelim, "Material Export Specification", "MaterialExportFile", "L:\Interfaces\Import\Inv\Test Files\MaterialExportFile.txt", True

End Sub

Is there a way to make it append the current date and time to the text file name (like: MaterialExportFile04162012_0814.txt or something like that.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

You mean something like this:

Private Sub Command18_Click()

Dim sOutput As String
sOutput = "L:\Interfaces\Import\Inv\Test Files\MaterialExportFile " & Format(Now, "mmddyyyy") & ".txt"

DoCmd.TransferText acExportDelim, "Material Export Specification", "MaterialExportFile", sOutput , True

End Sub

Open in new window


Danny
qbjgqbjgConsultant

Author

Commented:
Thanks, I will try it.
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
Just a note that

Format(Now, "mmddyyyy")

Does not include the Time. To do that, you would need to use something like

Format(Now, "mmddyyyy h:m:s")
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
<No points wanted>
If you really want to do this up right, I suggest using the international date format:
YYYY-MM-DD HH:nn:ss
as
Format(Now,"YYYYMMDDHHNNSS")
...so that the file names sort naturally/logically
qbjgqbjgConsultant

Author

Commented:
Thanks for all your help.
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
The accepted answer did not include the Date and TIME - it appended the Date ONLY to your file. Your question asked how to include the Date and Time.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial