Before update issue

punter

Registered User.
Local time
Today, 01:22
Joined
Nov 24, 2006
Messages
108
Hi,

I'm having an issue with getting some code to work. I have a form that has a command button that updates a table. The code is listed below:

Private Sub Add_Record_Click()




On Error GoTo Err_Add_Record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_Record_Click:
Exit Sub

Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click

End Sub


Here is my issue: I don't want the record to be updated if two parts of the form are not equal. The code I'm trying to enter is below:

If NZ (Me.Cartons) <> NZ (Me.Carton Total) Then
Msgbox "Error Message", vbcritical
Cancel = True

End If


It seems to me I should be able to enter that code before the first one. In practice it is not working that way. It is telling me I have a variable undefinded. Any thoughts?

Thanks

Eddie
 
Me.Carton Total

needs brackets since there is a space
Me.[Carton Total]
 
Thank you so much for your reply. I put the brackets in.

I'm getting an error on the Cancel = True portion. It is highlighting the Cancel and = part of the line. It is telling me the variable it not definded. Which variable do you think I should stick in there?

Thanks

Eddie.
 
Are you sure that the code you are listing is on the Form's BeforeUpdate event? Cancel is only available on certain events and the form's before update event is one of them.
 

Users who are viewing this thread

Back
Top Bottom