sub or function not defined

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
 
R

Rick Brandt

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.
 
W

Walter

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
 
R

Rick Brandt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top