Naming a file according to the date

jd_boss_hogg

Registered User.
Local time
Today, 19:30
Joined
Aug 5, 2009
Messages
88
Hi guys,

I'm a complete newby to VBA coding, and hoping someone here can help.

I currently have a peice of code that exports a file called "john.csv". However, i'd like this filename to actually carry the date that it was created in the name itself, so something like this... "john_01_09_2009.csv". It doesn't have to match that formatting, just something that obviosuly ties in with the date. Any clues on how to do it?

Currently, here is the line that exports the file. I presume that i need to set a string variable to replace the file name constant.

DoCmd.OutputTo acOutputQuery, "NewCSVExport", acFormatXLS, "c:\john.csv"

Thanks very much !
 
Try -

" & " " & Format(Date(),"ddmmyy")

between the file name and file extension

i.e. John " & " " & Format(Date(),"ddmmyy").csv
 
Brill - works a treat - thanks very much !
 
For sorting reasons I suggest you use ISO date format YYYYMMDD instead

Also keep in mind that spaces in filenames doesnt make all the systems happy.
 
Brill - works a treat - thanks very much !

Thats ok!!!

Like namliam says it may be better to use YYYYMMDD formatting and you could replace the space with an underscore, so:-

John " & "_" & Format(Date(),"yyyymmdd").csv
 
For sorting reasons I suggest you use ISO date format YYYYMMDD instead

Also keep in mind that spaces in filenames doesnt make all the systems happy.

I STRONGLY agree on both counts. Especially, as I am a user of unix, Windows, and Mac systems, spaces in filenames can cause uncountable headaches. Stick to only letters, numbers, dashes, and underscores in filenames and you'll be safe.

While an OS or software package claims it supports spaces in filenames, implementation is always spotty at best. Some functions will support spaces, some won't, especially old, archaic functions.
 
Stick to only letters, numbers, dashes, and underscores in filenames and you'll be safe.
I would stick to only Letters and numbers and then on ascii characters...
Dashes and underscores lives in their own world and are the root of all evil!
 

Users who are viewing this thread

Back
Top Bottom