How can I write the code if I don't know or don't want to write error number?
Private Sub cmdfirst_Click()
On Error GoTo FIRST
rs.MoveFirst
show_rec
FIRST:
If Err.Number = 3021 Then 'How can I modify the code here?
End If
End Sub
Printable View
How can I write the code if I don't know or don't want to write error number?
Private Sub cmdfirst_Click()
On Error GoTo FIRST
rs.MoveFirst
show_rec
FIRST:
If Err.Number = 3021 Then 'How can I modify the code here?
End If
End Sub
Not sure if I understand the question.
What has to be done when the error is raised?
Why not write the errors to a .txt file?
VB Code:
ErrorLog: Open App.Path & "\errorlog.txt" For Append As #1 Write #1, Format(Now, "C"), Err.Number, Err.Description, " Your Descriptiion" Close #1
On Error GoTo FIRST (This is ok)Quote:
Originally Posted by vbcode1980
If Err.Number = 3021 Then (In this sentence what should I write in the place of Err.Number = 3021 if I dont want to write the error number like this "3021".
Quote:
Originally Posted by seema_s
could do this,
VB Code:
On Error GoTo FIRST rs.MoveFirst show_rec Exit Sub FIRST: MsgBox Err.Description & " " & Err.Number
What exactly do you want the error handler to do for you?Quote:
Originally Posted by seema_s
You have a couple of options. First, you don't have to use any If statment at all.This will trap and log the error. Note, no code after the error will be executed.VB Code:
Private Sub Command1_Click() On Error Goto ErrTrap 'code for click event Exit Sub ErrTrap: 'use eusty's example Open "c:\ErrorLog.txt" For Append As #1 Print #1, Format(Now, "mm/dd/yyyy") & " " & Err.Number & " " & Err.Description Close #1 End Sub
If you want to trap for a specific error, as well as all other errors, then you can use the If statementAgain, no code will be executed after the line the error occurred on. If you want to trap and log the error, and continue code execution, then in your error trap, log the error, then add a Resume Next, which will continue executing the code after the line on which the error has occured.VB Code:
Private Sub Command1_Click() On Error Goto ErrTrap 'code for click event Exit Sub ErrTrap: If Err.Number = 3021 Then 'do something for this specific error Else 'do something else regardless of what the error is End If End Sub
Thanks a lot.Quote:
Originally Posted by Hack