create file for output + name it current date (1 Viewer)

stimpy

New member
Local time
Today, 18:51
Joined
Aug 2, 2000
Messages
8
I need to create a text file and name it the current date. I then need to have the results of a query exported to that file.
If a file with the same name already exists then it has to overwrite it.

I have attempted this by using the Open, Freefile, Print and Close commands. Unfortunately I am stuck and don't know where to go from here.
Any advice or code examples would be much appreciated.
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 18:51
Joined
Jun 16, 2000
Messages
1,954
This is how I would do it:

Private Sub MyButton_Click()
Dim filename As String
filename = Trim(Str(Year(Now()))) & "_" & Trim(Str(Month(Now()))) & "_" & Trim(Str(Day(Now()))) & ".txt"
If Dir("c:\Mydir\" & filename) <> "" Then Kill ("c:\Mydir\" & filename)
DoCmd.TransferText acExportDelim, "MySpecName", "MyTableOrQueryName", "c:\Mydir\" & filename
End Sub

I've assumed you want to export as a delimited text file, but if you want fixed width, you just change 'acExportDelim' to 'acExportFixed'.
You'll need to create an export specification, for details on this, see http://www.access-programmers.co.uk/ubb/Forum6/HTML/000077.html
(Actually this topic is about import specs, but the principle is the same)

HTH

Mike
 

Users who are viewing this thread

Top Bottom