Pb in my BeforeUpdate event (1 Viewer)

Emmanuelle

Registered User.
Local time
Today, 08:44
Joined
Mar 8, 2001
Messages
11
Hello everybody

I wrote a validation test in my beforeUpdate Event which DOES NOT WORK!!!! The user is prompted to enter a number if he leaves a textbox empty and I want the beforeUpdate event to be cancelled and the user be able to make its changes. However before the user can do anything, there is a message error:
you can't save this record at this time. BUT I DON'T WANT TO SAVE IT!!!
here is my code

If Me.Dirty Then
If IsNull([Updatelevel]) Then
MsgBox "Please enter a number in the update level"
Me.Undo
Cancel = True
Exit Sub
End If
end if

what is wrong in my code?
thanks for your help
emmanuelle
 

Peter D

Registered User.
Local time
Today, 08:44
Joined
Sep 7, 2000
Messages
188
When you set Cancel = True from the BeforeUpdate event proc, that will cancel the update. So, I think you don't need the me.undo in there.

Also, you may want to check the field for the empty string ("").

I.e.:
if isnull(mycontrol) or mycontrol = "" then
...

Hope this helps,

Peter De Baets
Peter's Software - MS Access tools http://www.peterssoftware.com
 

Emmanuelle

Registered User.
Local time
Today, 08:44
Joined
Mar 8, 2001
Messages
11
thanks Peter for your answer, but my problem remains. What I forgot to say is that this code is in the form_BeforeUpdate and the message comes up when I close the form, Access tries to save the record after the BeforeUpdate procedure and before the close event, thing I don't want. If the BeforeUpdate fails, I want the form to remain open and allow the user to make the changes, therefore a step before the BeforeUpdate.

Does that make sense? and is it possible
thanks
 
R

Rich

Guest
Use the control's before update
If IsNull(Me.Textboxname) Then
Cancel = True
MsgBox "Please enter a number in the update level"
End If
 

Users who are viewing this thread

Top Bottom