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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save a textfile as date 2

Status
Not open for further replies.

vicky666

Programmer
Feb 13, 2003
22
GB
HI guys have a small problem, basically i have this data that I want to save into a textfile which will be called whatever the date happens to be, but because the date contains "\" these things, it say file path not found. The code below works as long as you put your own filename in, but doesnt when it tries to enter the date, please help cheers


Open App.Path & "\" & Date & ".txt" For Append As #2
StrAlerts = FrmSecurityView.TxtAlerts.Text
Write #2, StrAlerts
'Close #2

vix
 
could you not parse out the "\" 's

mydate = Date
mydate = Replace(mydate, "/", "")

good luck If somethings hard to do, its not worth doing - Homer Simpson
 
Although you've haven't indicated that any of your previous posts were helpful, I would nevertheless suggest that you try the following:

Open App.Path & "\" & Format(Date, "yyyy-mm-dd") & ".txt" For Append As #2 Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Vicky Vicky Vicky,

You didn't know this, and you didn't ask your beloved boyfriend???
He will be heartbroken :p

Keep well

Sam
 
[lol]

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
There are many ways to do this, I would code it like this...

Dim FilesName as String
FilesName = Format$(Now,"MM_DD_YYY")
Open App.Path & "\" & FilesName & ".txt" For Append As #2
StrAlerts = FrmSecurityView.TxtAlerts.Text
Write #2, StrAlerts
'Close #2
 
Your fix is simple. Instead of using DATE use DATE$. VB retains the old QBasic DATE$ function which gives you the date in MM-DD-YYYY format. Simple as can be. DATE is the new VB function and uses MM/DD/YYYY format.
 
To expand on my post above:

Open App.Path & "\" & Date$ & ".txt" For Append As #2
StrAlerts = FrmSecurityView.TxtAlerts.Text
Write #2, StrAlerts
'Close #2

Results in 08-01-2003.txt being created or appended to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top