Full Version: Write a txt file
UtterAccess Discussion Forums > Microsoft® Access > Access Automation
kodan
Hi to all.
With the help of many people in UA, I found the code to write text file.
I want use it as a simple log to record date and time users logs in.

Dim strFile As String
Dim fhand As Integer

strFile = "UsersLog.txt"
fhand = FreeFile
Open strFile For Output As #fhand

LogDT = "[" & Now & "] -- " & UCase(strUserID)
Print #fhand, LogDT
Close #fhand

This is part of the code that mishej suggested me (thanx!) and works fine, but every time the routine write the file, replace it with new data instead of adding a new line in the existing text file.

Any ideas ?

Thanx in advance
BenPurser
Don't know squat about this, but a quick perusal of the Help turned up the Append mode, so this line:

Open strFile For Output As #fhand

you might want to change to

Open strFile For Append As #fhand

I don't know what happens if you try to use Append before the file is first created. It may or may not create it if it doesn't already exist.

HTH
Ben
truittb
FYI

QUOTE
I don't know what happens if you try to use Append before the file is first created. It may or may not create it if it doesn't already exist.


If the file specified by pathname doesn't exist, it is created when a file is opened for Append, Binary, Output, or Random modes
kodan
Ok everything works very good ! thanx to all
rack
using '97 and coming up with "User-type type not defined" on the Print command, this looks like a reference problem, anyone know which reference would correct this?

Thanks
Rack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.