Writing date and time to text file

G

Guest

I want to keep a log of who used my database and when. I can record the user
name in the txt file but the date is written to the file as a series of
question marks eg “??? ?? ?â€

Dim f As Long
f = FreeFile
Open "C:\testfile.txt" For Append Shared As #f
Print #f, fOSUserName & " " & fGetFullNameOfLoggedUser & " " & Date
Close #f

The above code results in this being written to the text file:

fisches Seth Fischer ??? ?? ?


Thanks for any help

Seth
 
J

Jonathan S via AccessMonster.com

Perhaps you could try format()? I haven't tried doing this myself, but
perhaps it is not writing out a formatted string, but the underlying hex-
value? Try format (date, "YYYY/MM/DD") and see if that helps.

Jonathan Scott
 
R

Ron Weiner

Seth

Why are you using an external text file? Why not create a table (tblLogIn)
and put all of this information there? After all Access IS a database.

strSql = INSERT INTO tblLogIn (UserName, FullName, " _
& "LogInDate) VALUES ('" & fOSUserName & "', '" _
& fGetFullNameOfLoggedUser & "', #" & date & "#)"
CurrentDb.Execute strsql, dbFailOnError

Half the code, and it's the "Access Way"!
 
D

Douglas J Steele

There are plenty of reasons to write logs to text files external to the
database. For one thing, it's easy to tell the user to e-mail a particular
file if you don't have access to the MDB itself!

Seth: Does the Date function work on your machine? Sometimes a problem with
the References can cause the Date function to stop working, as can having
anything in your application named Date (i.e. a field in a table, a control
on a form, a variable, a function, etc.).

Go to the Immediate Window (Ctrl-G), type ?Date and hit Enter. What happens?
 
G

Guest

I’ve done some experimenting:

If it print the date at the end of the line it comes out as question marks

Print #f, fOSUserName & ", " & fGetFullNameOfLoggedUser & ", " &
Format(Date, "dd mmm yyyy")
= "fisches, Seth Fischer? ?? ??? ? ?"


BUT if I print the date at the beginning of the line it comes out correctly

Print #f, Format(Date, "dd mmm yyyy") & ", " & fOSUserName & ", " &
fGetFullNameOfLoggedUser
= "23 Sept 2005, fisches, Seth Fischer"

It’s not just the date this happens with it’s all so the machine name.

Cheers,
Seth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top