|
-
Jan 16th, 2006, 07:57 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Code for ERROR HANDLING !!!
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
-
Jan 16th, 2006, 08:05 AM
#2
Re: Code for ERROR HANDLING !!!
Not sure if I understand the question.
What has to be done when the error is raised?
I code C#....

-
Jan 16th, 2006, 08:10 AM
#3
Lively Member
Re: Code for ERROR HANDLING !!!
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
Steve
No trees were cut down or harmed in the posting of this message. A lot of electrons were, however, severely inconvenienced.
-
Jan 16th, 2006, 08:12 AM
#4
Thread Starter
Fanatic Member
Re: Code for ERROR HANDLING !!!
 Originally Posted by vbcode1980
Not sure if I understand the question.
What has to be done when the error is raised?
On Error GoTo FIRST (This is ok)
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".
-
Jan 16th, 2006, 08:16 AM
#5
Re: Code for ERROR HANDLING !!!
 Originally Posted by seema_s
On Error GoTo FIRST (This is ok)
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".
could do this,
VB Code:
On Error GoTo FIRST
rs.MoveFirst
show_rec
Exit Sub
FIRST:
MsgBox Err.Description & " " & Err.Number
-
Jan 16th, 2006, 08:20 AM
#6
Re: Code for ERROR HANDLING !!!
 Originally Posted by seema_s
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
What exactly do you want the error handler to do for you?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 16th, 2006, 08:21 AM
#7
Re: Code for ERROR HANDLING !!!
You have a couple of options. First, you don't have to use any If statment at all.
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
This will trap and log the error. Note, no code after the error will be executed.
If you want to trap for a specific error, as well as all other errors, then you can use the If statement
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
Again, 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.
-
Jan 17th, 2006, 09:54 AM
#8
Thread Starter
Fanatic Member
Re: Code for ERROR HANDLING !!!
 Originally Posted by Hack
You have a couple of options. First, you don't have to use any If statment at all.
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
This will trap and log the error. Note, no code after the error will be executed.
If you want to trap for a specific error, as well as all other errors, then you can use the If statement
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
Again, 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.
Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|