Record an Error Log to a Plain txt file

  • Thread starter Thread starter Tom via AccessMonster.com
  • Start date Start date
T

Tom via AccessMonster.com

Hello

Can somebody please provide me the code to record certain text (example:
error tracking) to a plain text file?

I want to programmatically open myErrorLog.txt and input text at the end of
the file. Something like:


Error: Error Message
Time: Time
Date: Date
Procedure: The Procedure and object which the error occured


Error: Error Message
Time: Time
Date: Date
Procedure: The Procedure and object which the error occured

and so on...

So the code should some how "see" where to input 3 soft-return characters and
the errror log....

Thank you for any help
 
Sub ErrorLogging( _
ErrObj As VBA.ErrObject, _
ErrorSource As String _
)

Dim intFile As Integer
Dim strFile As String

strFile = "C:\Some Folder\myErrorLog.txt"
intFile = FreeFile()

Open strFile For Append As #intFile
Print #intFile, "Error: " & Err.Description
Print #intFile, "Time: " & Time()
Print #intFile, "Date: " & Date
Print #intFile, "Procedure: " & ErrorSource
Print #intFile, ""
Close #intFile

End Sub


Unfortunately, Access provides no way of knowing where the error occurred,
so you'll have to pass the name of the routine (as ErrorSource) every time
you call this routine.
 
Back
Top