On Tue, 23 Sep 2008 20:22:02 -0700, Afrosheen wrote:
> I have a check box that when I check it it gives me an error. The error is:
> Error 0() in procedure Trainer_Click. Here is the code:
>
> '---------------------------------------------------------------------------------------
> ' Procedure : Trainer_Click
> ' Author : 3710opr1
> ' Date : 9/23/2008
> ' Purpose :
> '---------------------------------------------------------------------------------------
> '
> Private Sub Trainer_Click()
> 10 On Error GoTo Err_Trainer_Click
> 20 If Trainer Then
> 30 cmdToggle.Enabled = True
> 40 Else
> 50 cmdToggle.Enabled = False
> 60 End If
>
> Err_Trainer_Click:
> 70 Call LogError(Err.Number, Err.Description, "Trainer_Click()")
> 80 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
> procedure Trainer_Click of VBA Document Form_Copy of frm_roster"
> End Sub
>
> I get the error if I click on or off. I have another form with the same code
> and it works fine.
I doubt it is the same code.
>
> Thanks for reading this.
Your code runs directly into the Err_Trainer_Click even if there is no
error. You should exit the sub before that point, so that unless there
is an error, the error handler does not run.
You should also clear the error, if there is one, and resume
somewhere.
\
Private Sub Trainer_Click()
10 On Error GoTo Err_Trainer_Click
20 If Trainer Then
30 cmdToggle.Enabled = True
40 Else
50 cmdToggle.Enabled = False
60 End If
65 Exit_Sub:
66 Exit Sub
Err_Trainer_Click:
70 Call LogError(Err.Number, Err.Description,
Trainer_Click()")
80 MsgBox "Error " & Err.Number & " (" & Err.Description & ")
in procedure Trainer_Click of VBA Document Form_Copy of frm_roster"
85 Resume Exit_Sub ' clear the error and exit the sub
End Sub
|