Use Current Date on text file

  • Thread starter Thread starter Sammy via AccessMonster.com
  • Start date Start date
S

Sammy via AccessMonster.com

I'm have a button on a form that will transfer text from a query to a text
file on my c:drive named "testfile05-01-07.txt"

I need to transfer text everyday, once a day. I don't want to overwrite the
file each time. Instead I want to create a new file each day with the above
name but the current date: example testfile05-02-07, then on the next day a
new file should be named "testfile05-03-07", etc..

Here's my code to transfer to the text file:
DoCmd.TransferText acExportDelim, , "QryExport", "c:\temp\testfile05-01-07.
txt", True

Please help.

Thanks,
Sammy
 
I'm have a button on a form that will transfer text from a query to a text
file on my c:drive named "testfile05-01-07.txt"

I need to transfer text everyday, once a day. I don't want to overwrite the
file each time. Instead I want to create a new file each day with the above
name but the current date: example testfile05-02-07, then on the next day a
new file should be named "testfile05-03-07", etc..

Try this:

DoCmd.TransferText acExportDelim, , "QryExport", "c:\temp\testfile" & Cstr(Date) & ".txt", True

If you do this more than once a day, of course, this would overwrite the existing file. If that's the case, you can use
Now instead of Date ... Now would stamp it with the Time and Date ...

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Sammy, here is a suggestion for you.
Scott's answer is partially correct, but the problem is it will create a
file name like
c:\temp\testfile05\01\2007.txt
Which is probably not what you want. There are issues with the \ in file
names. In addition, to easily locate the file visually, I would suggest you
use a year, month, day format. It will sort them in date order that way.
Here is what I would use:

DoCmd.TransferText acExportDelim, , "QryExport", "c:\temp\testfile" &
Format(Date,"yy-mm-dd") & ".txt", True
 
Back
Top