G
Guest
I have code in the AfterUpdate event of a control with an error handler.
when I update the control, I get a "compile error: label not defined". The
Private Sub MileageDescription_AfterUpdate() line is highlighted in yellow
and the
Resume Exit_MileageDescription_AfterUpdate line is highlighted in blue.
I have compared this to other error handlers and haven't been able to spot
anything wrong. If I comment the Resume Exit_MileageDescription_AfterUpdate
line, the rest of the code works as it should so I don't know why the error
line is even coming into play. Here is the code I have. Could someone tell
me what my problem is?
Private Sub MileageDescription_AfterUpdate()
On Error GoTo Err_MileageDescription_AfterUpdate
If Me.MileageDescription = "State Line" Then
Me.State_Cover.Visible = False
Me.State.Enabled = True
Me.State.SetFocus
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = False
Me.Location.Visible = False
Me.Location_Label.Visible = False
ElseIf Me.MileageDescription = "Fuel" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = True
Me.Gallons.Visible = True
Me.Gallons_Label.Visible = True
Me.Gallons.SetFocus
Me.Amount.Enabled = True
Me.Amount.Visible = True
Me.Amount_Label.Visible = True
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = False
Me.Location.Visible = False
Me.Location_Label.Visible = False
ElseIf Me.MileageDescription = "Stop" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = True
Me.StopPurpose.Visible = True
Me.StopPurpose_Label.Visible = True
Me.StopPurpose.SetFocus
Me.Location.Enabled = True
Me.Location.Visible = True
Me.Location_Label.Visible = True
ElseIf Me.MileageDescription = "Trip End" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = True
Me.Location.Visible = True
Me.Location_Label.Visible = True
End If
Exit Sub
Err_MileageDescription_AfterUpdate:
MsgBox Err.Description
'Resume Exit_MileageDescription_AfterUpdate
End Sub
I realize now this could be done more efficiently probably with SELECT CASE
but it's working, except for the error part, and I've been hesitant to mess
with it
when I update the control, I get a "compile error: label not defined". The
Private Sub MileageDescription_AfterUpdate() line is highlighted in yellow
and the
Resume Exit_MileageDescription_AfterUpdate line is highlighted in blue.
I have compared this to other error handlers and haven't been able to spot
anything wrong. If I comment the Resume Exit_MileageDescription_AfterUpdate
line, the rest of the code works as it should so I don't know why the error
line is even coming into play. Here is the code I have. Could someone tell
me what my problem is?
Private Sub MileageDescription_AfterUpdate()
On Error GoTo Err_MileageDescription_AfterUpdate
If Me.MileageDescription = "State Line" Then
Me.State_Cover.Visible = False
Me.State.Enabled = True
Me.State.SetFocus
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = False
Me.Location.Visible = False
Me.Location_Label.Visible = False
ElseIf Me.MileageDescription = "Fuel" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = True
Me.Gallons.Visible = True
Me.Gallons_Label.Visible = True
Me.Gallons.SetFocus
Me.Amount.Enabled = True
Me.Amount.Visible = True
Me.Amount_Label.Visible = True
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = False
Me.Location.Visible = False
Me.Location_Label.Visible = False
ElseIf Me.MileageDescription = "Stop" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = True
Me.StopPurpose.Visible = True
Me.StopPurpose_Label.Visible = True
Me.StopPurpose.SetFocus
Me.Location.Enabled = True
Me.Location.Visible = True
Me.Location_Label.Visible = True
ElseIf Me.MileageDescription = "Trip End" Then
Me.State_Cover.Visible = True
Me.State.Enabled = False
Me.Gallons.Enabled = False
Me.Gallons.Visible = False
Me.Gallons_Label.Visible = False
Me.Amount.Enabled = False
Me.Amount.Visible = False
Me.Amount_Label.Visible = False
Me.StopPurpose.Enabled = False
Me.StopPurpose.Visible = False
Me.StopPurpose_Label.Visible = False
Me.Location.Enabled = True
Me.Location.Visible = True
Me.Location_Label.Visible = True
End If
Exit Sub
Err_MileageDescription_AfterUpdate:
MsgBox Err.Description
'Resume Exit_MileageDescription_AfterUpdate
End Sub
I realize now this could be done more efficiently probably with SELECT CASE
but it's working, except for the error part, and I've been hesitant to mess
with it