From Close versus docmd.close

R

Rick Allison

I have a close button that runs docmd.close.

I also have the form close (X) option enabled.

The form is bound. When I type something into the form and press the close
button, the one I created, the form closes with no issue. When I use the
forms close (X) option I receive warning message saying the record cannot be
saved at this time because a related record is required. (This is okay and
not the issue).

I tried me.closebutton = false at form open and it says I cannot do this. I
don't want to set this option in design mode.

Why does the docmd.close just close the form but the close (X) option wants
to display an error. I tried setting warning off on form open but that did
not work.

I'm using Access 2000.

Thanks,
 
R

Rick Brandt

Rick Allison said:
I have a close button that runs docmd.close.

I also have the form close (X) option enabled.

The form is bound. When I type something into the form and press the close
button, the one I created, the form closes with no issue. When I use the
forms close (X) option I receive warning message saying the record cannot be
saved at this time because a related record is required. (This is okay and
not the issue).

I tried me.closebutton = false at form open and it says I cannot do this. I
don't want to set this option in design mode.

Why does the docmd.close just close the form but the close (X) option wants
to display an error. I tried setting warning off on form open but that did
not work.

I'm using Access 2000.

LOOONG standing bug in Access. If you have your own close button you need its
code to explicitly include a save...

Me.Dirty = False
DoCmd.Close acForm, Me.Name

or

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, Me.Name

Otherwise, records that *should* raise the error that you see with the standard
close [X] button are just silently discarded with your button. With the
additional line you will get an error raised by the explicit save (which you can
handle as desired). The two examples above would each raise a different error,
but are otherwise equivalent.
 
A

Allen Browne

Rick this is a very long-standing bug in Access, where the form silently
*loses* your entry if it cannot be saved. The X button correctly gives you a
warning if the entry will be lost.

More info in:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html
 

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