Date/timestamp on exported file name.

jomuir

Registered User.
Local time
Today, 11:58
Joined
Feb 13, 2007
Messages
154
I have a form where users enter the data, a query does some calculations in the background and then they can click on a button to export a report into a text form – this is required as the data requires being in a specific format for printing.

Is there a way of putting a date/timestamp in the name of the file that has been exported? (At the moment the files is called ManualReq.txt, and I would like it to be ManualReq_20080414_1500.txt i.e. 14th April 2008 a15:00)

Private Sub Export_to_Text_Click()
On Error GoTo Err_Export_to_Text_Click

Dim stDocName As String

stDocName = "ManualReq"
DoCmd.OutputTo acReport, "ManualReq", acFormatTXT, "X:\Printer1423\Printer_Queue1\ManualReq.txt", True

Exit_Export_to_Text_Click:
Exit Sub

Err_Export_to_Text_Click:
MsgBox Err.Description
Resume Exit_Export_to_Text_Click

End Sub
 
Concatenate the formated Datetime to your filename

example

MyFilename="ManualReg" & "_" & Format(yourDate,"yyyymmdd") & ".doc"

would produce Manualreg_20080414.doc
 
Cannot get this to work, it just saves the file as "ManualReq_.txt" I will keep on working on this...


Also on the same track, would it be possible enter a field name instead of the date stamp......I have an unique field for all these records, so could I use that. ManualReq_00228834.txt, where "00228834" is unique to all the records in this report/export - would that be easier (probably better for me users)

Okay, got the first part working, the date and time stamp:-

ManualReq_" & Format(Date, "yyyymmdd") & "_" & Format(Time, "hhmmss") & ".txt", True

Still wondering if I could do it with the unique number for each set of records - field name is "CallID"
 
Last edited:
to number the files you could

EITHER store a lookupnumber in your database to get the next file number, incrementing by one each time

or

FIND the highest number currently in the folder, and increment that.

Just a matter of taste really - the first may be more reliable, as files may not remain in the folder for ever
 
replace the formatted date with the name of the control

MyFilename="ManualReg" & "_" & me!YourID & ".doc"
 

Users who are viewing this thread

Back
Top Bottom