DoCmd.Close and no error msg

G

google3luo359

I have a DoCmd.Close button to close a form that does close its form.
However a desired error msg. is not shown despite having
DoCmd.SetWarnings True at the top of the function.

If one attempts to add a record that violates a field's property, the
field correctly does not accept it. However the form is closing without
notifying the user that the record was _not accepted!

Strangely, when the 'x' in the top corner is used to close the form,
Access notifies the user that the record was not accepted.

How can I get Access to notify the user when using the command button?
Once that is working properly I'd like to use my own message instead of
Access'.

TIA Ric
 
R

Rick Brandt

I have a DoCmd.Close button to close a form that does close its form.
However a desired error msg. is not shown despite having
DoCmd.SetWarnings True at the top of the function.

If one attempts to add a record that violates a field's property, the
field correctly does not accept it. However the form is closing
without notifying the user that the record was _not accepted!

Strangely, when the 'x' in the top corner is used to close the form,
Access notifies the user that the record was not accepted.

How can I get Access to notify the user when using the command button?
Once that is working properly I'd like to use my own message instead
of Access'.

TIA Ric

Bug that has been around for several versions. In the code of your button do an
explicit save first with either...

Me.Dirty = False
or
DoCmd.RunCommand acCmdSaveRecord

Either will work, but with different error messages if the record cannot be
"legally" saved.
 
G

google3luo359

Rick Brandt wrote:

.. In the code of your button do an
explicit save first with either...

Me.Dirty = False
or
DoCmd.RunCommand acCmdSaveRecord

Either will work, but with different error messages if the record cannot be
"legally" saved.


Thanks Rick.
I tried DoCmd.RunCommand acCmdSaveRecord
and got " The command "Save record' isn't available now".
Not sure why.

Anyways I then tried Me.Dirty = False and that worked, so I'm sticking
with it.
Thanks again!

Ric
 

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