I want to get the exact syntax that cause an error. I am using the code below. I can trap the easy errors such as
* Error Description
* Error Number
* Date Error Occurred
* The control that caused the error
The most useful information would be the line of code that causes the error.
In my example below this is "test = Me!Text + Me!Number", adding text to a number. If this could be transferred into a variable then it would be really useful.
Each command must be stored in some property of the form, or control. I've tried looking in books, etc and also using the debug but have not come up with anything.
I even though about using the execute command to pass each line of code as a string but that would be impractical. The other way is get the code to break on the error, but this isn't very professional.
If anyone can help me here I would be most appreciative. Thanks.
Can anyone help me
--------
- Code -
--------
Private Sub Command0_Click()
' Error handler
On Error GoTo errHand
Dim rstError As Recordset
Dim dbs As Database
Dim test
Dim sqlstr
Dim strDate As String
Dim control
Dim strControlName
' line to cause error
test = Me!Text + Me!Number
' Error handler
errHand:
Set control = Screen.ActiveControl
strControlName = control.Name
MsgBox strControlName
MsgBox "Any Error Has Occurred In The Application - Please Contact Your Support Staff", , "System Error"
Set dbs = CurrentDb
strDate = CDate(Date)
sqlstr = "Insert into T_Errors (ErrorMessage, ErrorNumber, FormName, ErrorDate) values ('" + Err.Description + "','" + str(Err.Number) + "','" + Me.FormName + "','" + strDate + "')"
dbs.Execute (sqlstr)
End Sub
* Error Description
* Error Number
* Date Error Occurred
* The control that caused the error
The most useful information would be the line of code that causes the error.
In my example below this is "test = Me!Text + Me!Number", adding text to a number. If this could be transferred into a variable then it would be really useful.
Each command must be stored in some property of the form, or control. I've tried looking in books, etc and also using the debug but have not come up with anything.
I even though about using the execute command to pass each line of code as a string but that would be impractical. The other way is get the code to break on the error, but this isn't very professional.
If anyone can help me here I would be most appreciative. Thanks.
Can anyone help me
--------
- Code -
--------
Private Sub Command0_Click()
' Error handler
On Error GoTo errHand
Dim rstError As Recordset
Dim dbs As Database
Dim test
Dim sqlstr
Dim strDate As String
Dim control
Dim strControlName
' line to cause error
test = Me!Text + Me!Number
' Error handler
errHand:
Set control = Screen.ActiveControl
strControlName = control.Name
MsgBox strControlName
MsgBox "Any Error Has Occurred In The Application - Please Contact Your Support Staff", , "System Error"
Set dbs = CurrentDb
strDate = CDate(Date)
sqlstr = "Insert into T_Errors (ErrorMessage, ErrorNumber, FormName, ErrorDate) values ('" + Err.Description + "','" + str(Err.Number) + "','" + Me.FormName + "','" + strDate + "')"
dbs.Execute (sqlstr)
End Sub