Error Handling Error

Triscuit

Registered User.
Local time
Yesterday, 20:44
Joined
Jul 20, 2010
Messages
27
I've looked up a lot of error handling code and used the same error handling code in other areas of my project but this one ignores the "On Error" and still gives me the runtime error. Why?

This code handles simple Calendar control and i'm using it with a subform control. As a workaround I'm error handling the error and using my workaround for the subform.





Code:
Private Sub ocxCalendar_Click()
On Error GoTo Err_subForm
cboOriginator.Value = ocxCalendar.Value
cboOriginator.SetFocus
ocxCalendar.Visible = False
Set cboOriginator = Nothing
Exit_subForm:
    Exit Sub
Err_subForm:
Select Case Err.Number
    Case 91
        Me.subfrmCalibrationAvgResponse.Form!dateLot.Value = ocxCalendar.Value
        ocxCalendar.Visible = False
        Set cboOriginator = Nothing
        Me.subfrmCalibrationAvgResponse.Form!dateLot.SetFocus
        Resume Exit_subForm
    Case Else
        Resume Exit_subForm
End Select

End Sub
 
We can't tell you the answer to your question if you don't give us either the text of the error or a screenshot of the error. We can't see what you see so remember you have to give us sufficient data to help.
 
Here's the image.

Upon clicking in the Calendar it gives the '91' error, Object Variable Not set.

However on this error it should go to the error handler and the Case 91 should operate from there.
 

Attachments

Are you creating cboOriginator via code? Or is it a control on your form?

I don't see the need to use this:

Set cboOriginator = Nothing

And that might be causing the problem.
 
CboOriginator is a global variable for the Main Form and is set to the control from the On_Mouse Down of that control.

For example for the Main form Date of Calibration:

Code:
Private Sub dateCalibration_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = dateCalibration
ocxCalendar.Visible = True
ocxCalendar.SetFocus


If Not IsNull(cboOriginator) Then
   ocxCalendar.Value = cboOriginator.Value
Else
   ocxCalendar.Value = Date
End If


End Sub

This is a problem in the subform for the Date Lot, because I don't think the cboOriginator value from the subform Date Lot mouse down function can be read by the Main form calendar On click method. Therefore I created the error handling to take the error and implement a workaround.

Here's the subform Date on mouse down code:

Code:
Private Sub dateLot_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = Me.dateLot
Me.Parent!ocxCalendar.Visible = True
Me.Parent!ocxCalendar.SetFocus

If Not IsNull(cboOriginator) Then
   Me.Parent!ocxCalendar.Value = cboOriginator.Value
Else
   Me.Parent!ocxCalendar.Value = Date
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom