Form closing unexpectedly without error

R

Rémi

Morning all. I'm seeing something really strange on a form I'm
reviewing, wondering if anyone can offer any suggestions. Access XP/
Windows XP.

I'm opening the form to add a new record with:

DoCmd.OpenForm "frmInventoryItem", _
DataMode:=acFormAdd, windowmode:=acWindowNormal

Only one field on this form is required. If I enter the required
field, everything happens as I would expect. If I do not fill it in,
then:

* If I close the form by clicking on the "x" in the upper right
corner, I'm prompted twice: once that "The field 'BLAH' cannot contain
a Null value because the Required property for this field is set to
True.", and once for "You can't save this record at this time.

* BUT if I close the form by clicking on my "Close" command button,
no warnings or error messages come up, and the form simply closes
without providing any cue that something was wrong. This is the whole
of my close button's click event handler:

Private Sub cmdClose_Click()
DoCmd.Close
End Sub

I've tried sticking a breakpoint in Form_Error, but it doesn't seem to
fire either.

I have made the form's autonumber field visible, to see if it provides
any clues as to what's happening... As soon as I enter any optional
field, it gets assigned a value (as expected). But when I click the
"Close" button, it reverts to "(Autonumber)" once again.

Frankly, I'm at a bit of a loss - the only thing I've been able to do
is force a Refresh in cmdClose if the form is Dirty - which does
provide me with an error if the required field isn't filled out, as I
would hope.

Am I missing something obvious here? Anyone seen this before?

Regards,
Remi.
 
A

Allen Browne

Join the queue, Remi. Believe it or not, this bug has been in Access from
the beginning.

I've tried for years to get MS to fix this, but without success. So the best
I can do is warn people about this:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html
 
R

Rémi

Allen,
I took a look at your bug page, and I will make one note: #3 doesn't
appear to be useless anymore... I'm calling Refresh and I am getting
an error message if the required field is not filled out. Don't know
if there are other scenarios where errors would not be thrown.

Regards,
Remi.
 
A

Allen Browne

Thanks Remi.

That's a really old article, and Refresh has been working for the last 4
versions of Access (from memory.)

Appreciate you pointing this out. Article updated.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Allen,
I took a look at your bug page, and I will make one note: #3 doesn't
appear to be useless anymore... I'm calling Refresh and I am getting
an error message if the required field is not filled out. Don't know
if there are other scenarios where errors would not be thrown.

Regards,
Remi.
 

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