[RESOLVED] Help: What is the easiest way to have Error write to an error log.txt
Hi ALL
I am a beginner in this..
I found the easiest to trap an error is just create a message box
ErrTrap:
MsgBox "Error trying to update the current record: " & Err.Description, vbCritical + vbOKOnly, App.Title
Now I want it to write this error to a file also ..
Could some one help me create a simple function that will write the message to an error.txt
it could be as primitive and simple ..
please help
thank you :wave:
Re: Help: What is the easiest way to have Error write to an error log.txt
Quote:
Originally Posted by ndondo
Hi ALL
I am a beginner in this..
I found the easiest to trap an error is just create a message box
ErrTrap:
MsgBox "Error trying to update the current record: " & Err.Description, vbCritical + vbOKOnly, App.Title
Now I want it to write this error to a file also ..
Could some one help me create a simple function that will write the message to an error.txt
it could be as primitive and simple ..
please help
thank you :wave:
Declare a string variable and store the above message to that
If you search the forum, you will see plenty of example on how to write to a text file. simply write the variable's data to text...
Re: Help: What is the easiest way to have Error write to an error log.txt
Code:
Private Sub Command1_Click()
On Error GoTo ErrTrap
'way cool code
Exit Sub
ErrTrap:
Open "c:\errorlog.txt" For Append As #1
Print #1, "An Error has occurred on " & Format(Now, "mm/dd/yyyy") & " in Command1_Click" & vbCrLf & vbCrLf
Print #1, "The error is: " & Err.Number & " " & Err.Description
Close #1
End Sub
Re: Help: What is the easiest way to have Error write to an error log.txt
Thank you! :)
I will try it and post back!
I appreciate it very much
Re: Help: What is the easiest way to have Error write to an error log.txt
You can add pretty much anything you want.
I write my errors back to an errorlog DB table which includes the username, machine name, date/time of the error, where in the program the error occured and what the error number and error description is.
I built a special Admin Only screen which will display all errors in the table, and when you click on one, it will give the details as logged. In addition, the table also includes a field for notes and resolutions so that anytime anyone with permissions to the errorslog table (like my boss :D ) can go in a take a look at what has been going on, and what has been done about it.
Re: Help: What is the easiest way to have Error write to an error log.txt
This Solved my Problem! :)
Thank you very much sir