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.
 

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

Back
Top