Problem with closing a form using a command button

  • Thread starter John S. Ford, MD
  • Start date
J

John S. Ford, MD

I've created a frmMainForm with an embedded sbfSubForm. I have set the
fields for the underlying tables as "Required". Therefore, if frmMainForm
is closed without all the fields being filled in, an error message is
triggered. This works fine if the main form is closed using the "Close"
button at the topexcept for one thing.

sbfSubForm has a command button that saves the work and closes frmMainForm.
Unfortunately, when this happens, the above-mentioned error message ISN'T
triggered if fields are incompletely filled out. The form simply closes and
the record for that entry isn't saved.

Any ideas as to why the error isn't triggered when I use my own command
button but IS when I close it with the built in close button at the top,
right corner of the main form?

Thanks in advance!

John
 
A

Allen Browne

John, this is a serious bug in Access, that has been there for ever. All my
attempts to get Microsoft to fix it have failed.

If it helps confirm you sanity, you can read about the bug in this article:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The article explains how to explicitly save the record before you use Close.
This triggers a trappable error, so the close does not execute if the save
fails.
 
J

John S. Ford, MD

Thanks Allan. I guess that answers my question (and confirms my sanity). I
wonder why MS has failed to fix this after such a long time.

I'll try the Me.Dirty = False trick you mentioned in your website to force a
record save.

Thanks again!
John
 

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