Forms and required fields

stuart_adair

Registered User.
Local time
Today, 12:15
Joined
Jan 13, 2009
Messages
57
Morning o' wise ones

I've got a form in a database but it wont respect required fields.

If I close the form using the x in the top right hand corner everything works fine and I get the message that I have to put data in certain fields before closing.

If I close the form using the button I've added -Form Operations - Close Form, then the form just closes without respecting the required fields and unless all fields are complete, the record isnt saved.

Can anyone advise please.
Thanks
Stu
 
Add some validation for fields in vba in before update event of form
 
Your problem is due to a long known bug in Access VBA. The command DoCmd.Close will, as you've found out, close a form without regard to validation of any fields. The really bad thing is it will do so dumping any records that fail validation and won't warn you. The answer is to force a record save before closing the form. In the code behind your button you'll see the line

DoCmd.Close

add a line so that it now reads

If Me.Dirty Then Me.Dirty = False
DoCmd.Close


and you should be set.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom