Close form button not enforcing required fields

L

lukebe

I have a basic form bound to a table. I have name and address as
mandatory in the table def. If I enter the name but not address then
click on the cross in the top right (built into access) of the form it
says "Cannot save record because address is required".
This is as I'd expect.

I have my own close button at the bottom of the form which has the
code:
DoCmd.close acForm, me.name
This closes the form without showing any errors and simply does not
save the data. If I enter all the required information it saves the
record fine. Just seems to not save if any required fields are missing
and does not show a warning.

Can anyone explain this anomily?
 
A

Allen Browne

Luke, this is a bug that has been in Access from the beginning. See:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

As the article points out, once you know of the problem, it is easy enough
to work around it. In your command button, force the save before you close.
That will fail if the record cannot be saved. Use error trapping to catch
that situations.

I've tried long and hard to get this addressed, but without success.
 
L

lukebe

Wow.. thankyou for pointing that out. I was unaware of this flaw.
But I can definately make it work confidently now.

Thanks from Newcastle NSW,
Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top