DoCmd.Close not saving data.

J

John Keith

"DoCmd.Close acForm, Me.Name, acSaveYes"

Using Access 2003

Help Text...
Note If a form has a control bound to a field that has its Required
property set to 'Yes,' and the form is closed using the Close method without
entering any data for that field, an error message is not displayed. Any
changes made to the record will be aborted. When the form is closed using the
Windows Close button, the Close action in a macro, or selecting Close from
the File menu, Microsoft Access displays an alert....

My underlying table has 13 fields, 2 of which are set as required (primary
key - SSN and Last Name), the other 11 fields are NOT required and nulls ARE
allowed. Why does the close command abort the changes unless ALL 13 fields
are not null?
 
J

Jeff Boyce

John

First, re-read the syntax explanation in Access HELP for the DoCmd.Close
acForm ... If I recall correctly, the "acSaveYes" setting saves, not the
data entered, but the structure of the form!

Commonly, entering data in a bound form (i.e., bound to data in a table or
in an updateable query), then moving to another record or closing the form
results in the data being saved.

How are you confirming that the data is not being saved?

If you aren't receiving any warnings, is there a chance your SetWarnings has
been turned off?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
L

Linq Adams via AccessMonster.com

First, Jeff is correct!

acSaveYes

does not save a record, it saves any design changes that have been made to an
object, in this case a form!

And what the Help is saying, in essence, is this:

If you close a form using

DoCmd.Close

and there are validation violations, such as a required field being Null,
Access will dump the record and close the form, ***without issuing any
warnings that this is happening***

To prevent this, you need to explicitly save the record first, so that if any
violations occur, Access will issue the appropriate warning. This will do it:

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

Linq Adams via AccessMonster.com

Meant to add that, ironically,

DoCmd.Close

is the code generated by the Command Button Wizard when you use it to create
a "Close" button in versions prior to 2007! After knowing for years that this
bug existed, they decided in version 2007 to fix it, at least as far as the
Command Button Wizard was concerned. I understand that the Wizard now
generates the code I gave in my last post.

And this has produced a new bug! If you use the Wizard to create a "Close"
button for an unbound form, i.e a menu/switchboard type form, the code

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

produces an error, because an unbound form ***doesn't have a Dirty
Property***
 

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