How to explicitly save a record?

M

mscertified

The database I am working on occasionally 'loses' a record. My theory is that
the record gets created but never saved rather than it gets saved and later
deleted (which seems much more unlikely). I do have lots of complex
validations in the 'before update' event and also I noticed that sometimes if
the user clicks the top right red X, the 'before update' actions are ignored.
Also, this database allows printing a record and this can be done before the
record has been saved. This code contains the following statement:
DoCmd.RunCommand acCmdSaveRecord
The reason this is done is to save the record so that the report has data.
Is this the correct command to use? I believe sometimes this command fails to
work as I have received messages like 'this command cannot be run now'.

I guess I'm looking for general advice on how to make sure records are
ALWAYS saved no matter what weird things the user does.
 
R

Rick Brandt

mscertified said:
The database I am working on occasionally 'loses' a record. My theory
is that the record gets created but never saved rather than it gets
saved and later deleted (which seems much more unlikely). I do have
lots of complex validations in the 'before update' event and also I
noticed that sometimes if the user clicks the top right red X, the
'before update' actions are ignored. Also, this database allows
printing a record and this can be done before the record has been
saved. This code contains the following statement: DoCmd.RunCommand
acCmdSaveRecord
The reason this is done is to save the record so that the report has
data. Is this the correct command to use? I believe sometimes this
command fails to work as I have received messages like 'this command
cannot be run now'.

I guess I'm looking for general advice on how to make sure records are
ALWAYS saved no matter what weird things the user does.

There is a long standing bug that if you have your own Close code for a form
and it contains a dirty record that cannot be validated that it is silently
discarded. This should NOT happen when the user uses the built in [X] to
close the form however.

If you have your own close code you just have to explicitly save the record
in that same code with...

Me.Dirty = False
or
DoCmd.RunCommand acCmdSaveRecord
 

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