sub or function not defined

  • Thread starter Thread starter Walter
  • Start date Start date
W

Walter

What is wrong in the following code to give this error? The
"Exit_ValidateOdometer" line is highlighted blue.

Private Sub ValidateOdometer(Cancel As Integer)
On Error GoTo Err_ValidateOdometer

'verify that odometer entry is not less than last
Dim varPrevOdometer As Variant

Set varPrevOdometer = Me.Parent!PrevOdometer

If Me.Odometer < varPrevOdometer Then
Cancel = True
Me.Odometer.SelStart = 0
Me.Odometer.SelLength = Len(Me.Odometer.Value)
MsgBox _
"The last odometer entered for this truck was " & _
varPrevOdometer & vbCrLf & _
"Please enter an odometer greater than or equal " & _
"to this.", , _
"Invalid Odometer Entry"
End If

Exit_ValidateOdometer
Exit Sub

Err_ValidateOdometer:
MsgBox Err.Number & Err.Description
Resume Exit_ValidateOdometer

End Sub
 
What is wrong in the following code to give this error? The ....
Exit_ValidateOdometer
Exit Sub

Err_ValidateOdometer:
MsgBox Err.Number & Err.Description
Resume Exit_ValidateOdometer

End Sub

As a line label "Exit_ValidateOdometer" needs to have a colon (:) after
it.
 
Now when I try to call "ValidateOdometer" I get an "Argument not optional"
error.

Private Sub Odometer_BeforeUpdate(Cancel As Integer)

Call ValidateOdometer

End Sub
 
Now when I try to call "ValidateOdometer" I get an "Argument not
optional" error.

Private Sub Odometer_BeforeUpdate(Cancel As Integer)

Call ValidateOdometer

End Sub

Your sub definition includes "Cancel As Integer" as an argument. Get rid
of that and remove it from your code. Looks like you copied an existing
event procedure to create your custom sub. The original needed "Cancel
as Integer". Your function does not.
 
Back
Top