dont save changes on form

accesshelpme

Registered User.
Local time
Today, 15:41
Joined
May 13, 2012
Messages
15
I add record button. This brings up a form shows a blank record with only one field automatically filled out at the top based on the client on the previous form. However, the problem is, is someone exits this form it saves the record with just that one client field filled out and the rest blank. I want it so if you exit out of the form without having anything in combo1(combobox)...it wont save the new record....THANKS
 
Use the BeforeUpdate event of the Form to issue a Me.UnDo if your criteria is not met.
 
Well i did this in the before update and its still not working...hmmmm

If Me.Combo1.Value = "" Then
Me.Undo
End If

I also tried


If Me.Combo1.Value = null Then
Me.Undo
End If
 
That's great! What did you finally end up using?
 
The correct method is to not populate any controls until the user dirties the record first. Therefore, defaults that you apply with code should be moved to the BeforeInsert Event. This event runs one time only for the first character the user types in any control. So since he dirtied the record, you can now apply the defaults without causing any confusion.

You still need code in the BeforeUpdate event to prevent a record from being saved if it is incomplete. Undoing the update isn't a good idea because it backs out all the changes the user made and will just cause more work for him if actually did want to save the record but made a mistake. Instead, cancel the update. This will leave the bad data in place where he can correct it.

Code:
If Me.SomeControl & "" = "" Then
    MsgBox "Please .....", vbOKOnly
    Me.SomeControl.SetFocus
    [COLOR="Red"]Cancel = True[/COLOR]
    Exit Sub
End If
 

Users who are viewing this thread

Back
Top Bottom