Question Creating Log File

shieriel

Registered User.
Local time
Today, 13:11
Joined
Feb 25, 2010
Messages
116
Hello to all again. I found a code on this forum that creates a log file and saved it automatically on c: drive everytime the database opens. I tried it on my form but i got an error and my form becomes hidden. Please verify the code on how to apply on my project:

CODE>:
Private Sub Form_Open(Cancel As Integer)
Dim FileNum As Integer
FileNum = FreeFile

Open "C:\DatabaseLog.txt" For Append As #1
Print #1, "Database opened by" & " " & Environ("UserName") & " " & "using computer" & " " & Environ("ComputerName") & " " & ": :" & " " & Now(); ""
Close FileNum

End Sub
Private Sub Form_Close()
Dim FileNum As Integer
FileNum = FreeFile

Open "C:\DatabaseLog.txt" For Append As #1
Print #1, "Database closed by" & " " & Environ("UserName") & " " & "using computer" & " " & Environ("ComputerName") & " " & ":---:" & " " & Now(); ""
Close FileNum

End Sub
 
if this file does not already exist, then i think the append option fails

try testing it first (with Dir)

if it exists, then use

open for append

if it doesnt exist, then use

open for output


============
try manually creating the log file with notepad - see if that fixes it.
 
if this file does not already exist, then i think the append option fails

try testing it first (with Dir)

if it exists, then use

open for append

if it doesnt exist, then use

open for output


============
try manually creating the log file with notepad - see if that fixes it.

ok i will try and give you update later. Thanks;)
 
Hi Gemma, i tried to create i textfile based on the code and it is now working fine. Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom