AfterUpdate (1 Viewer)

Dave Edwards

New member
Local time
Today, 14:23
Joined
Apr 3, 2000
Messages
8
Hi
I'm having a problem ensuring that the user enters valid data.
On a form after the user has input their values for several fields I am using AfterUpdate to check if they have a valid input according to the rules of the program.
For example if the totals of fields 1 and 2 are less than the total of fields 3 and 4 then an error box comes up and the focus returns to field1 of that row so that they can amend their entry. I have used the follow in AfterUpdate for the form.
Private Sub Form_AfterUpdate()
If (field1 + field2) > (field3 + field4) Then
MsgBox "Invalid Entry.", vbExclamation, "Error:"
field1.SetFocus
End IF
End Sub
This works fine, but if the user now tabs through the record onto the next row then AfterUpdate will not run as the user has made no changes to the row.
Any suggestions please.

[This message has been edited by Dave Edwards (edited 05-13-2000).]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:23
Joined
Feb 19, 2002
Messages
43,223
Putting edits in the AfterUpdate event of the form is like shutting the barn door after the horses have run out. It's too late, the record has already been saved.

Move your edit to the BeforeUpdate event of the form and in addition to displaying the message box, add the following line of code:
Cancel = True
What this does is cancel the update event so the record will not be saved until the edit is satisfied.

The Form's BeforeUpdate event is the last event fired before data is actually saved to a table. It is fired on both update and add.
 

Dave Edwards

New member
Local time
Today, 14:23
Joined
Apr 3, 2000
Messages
8
Thanks, this is exactly what I was after
 

Users who are viewing this thread

Top Bottom