Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming text file with current date 4

Status
Not open for further replies.

tmangin

Programmer
Oct 29, 2003
16
US
Does anyone know how to name a file with the current date?

I'm creating the text file this way:
Open "C:\iFtpSvc\Hms-ftppro\users\RCI27\Report.txt" For Output As 2

Instead of Report.txt, I want the name of that file to be the current date.

Thanks!
 
use :

Open "C:\iFtpSvc\Hms-ftppro\users\RCI27\" & now & ".txt" For Output As 2

this will do it.

BB
 
Try:
Dim strFileName as string
strFileName = "C:\iFtpSvc\Hms-ftppro\users\RCI27\" & date
Open strFileName For Output As 2
 
BiggerBrother & DrJavaJoe,
I tried both of your suggestions, but with each, nothing happens. The file is not created. In fact, it seems to freeze. I appreciate you sending the additional thread as well, however, I was hoping there would be a simpler way to do this. Any other suggestions?
Thanks so much!
 
It doesn't like the slashes given in the default date format try this instead:

Dim strFileName As String
strFileName = "C:\iFtpSvc\Hms-ftppro\users\RCI27\" & Format(Date, "mm-dd-yyyy") & ".txt"
Open strFileName For Output As #2
Print #2, "Test"
Close #2
 
I tend to use something similar to this
Code:
dim strFile as string
dim strPath as string

strPath = "C:iFtpSvc\Hms-ftppro\users\RCI27\"
strFile = strPath & Format(Now, "YYYYMMDD") & ".txt"

Open strFile for Output as 2

It is also better practice to use the Freefile function to obtain the file number (This is the as bit of the open statement)




Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
ARRRGH
DrJavaJoe is quicker on the draw...

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
The default date setting is probably giving you a date like "10/12/03"

The / isn't allowed in file names. Instead of Date use Format(Date, "dd-mm-yy") (or any other order that you want, but use hyphens not slashes)

Open "C:\fred" & Format (Date,"dd-mm-yy") & ".txt" For Output As 2

works fine for me


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Try BiggerBrother's suggestion but format the date as in
Code:
Open "C:\iFtpSvc\Hms-ftppro\users\RCI27\" & Format(now,"yyyymmddhhnnss") & ".txt" For Output As 2
Sometimes the formatting that windows automatically applies (usually your defined "Long Date") causes problems in a file name.
 
So it's unanimous "/" isn't allowed in file names and ditto on using the freefile function. :)
 
Sorry DJJ,
Looks like a multiple x-post!
[wink]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thanks DrJavaJoe, mattKnight, johnwm, and Golom for all of your help and suggestions.
I'm all fixed!
 
Glad we all could help!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top