DoCmd.DoMenuItem acFormBar, acFile, acSaveRecord: Substitute fromVBA?

P

PeteCresswell

In VBA behind a form, I'm doing a DoCmd.DoMenuItem acFormBar, acFile,
acSaveRecord before updating the back end from the work table the
form is based on.

It works... sort of....

The rub comes when stepping though code. It throws a "2046: The
command or action 'SaveRecord' isn't available now" - which makes
sense, seein that I'm in a code window and not the form.

Sounds like I'm being sloppy but this is the only way I know.

Is there a more robust way to make sure that values in the fields on
my form are flushed to the work table before I do something that
assumes they are?
 
D

Dirk Goldgar

PeteCresswell said:
In VBA behind a form, I'm doing a DoCmd.DoMenuItem acFormBar, acFile,
acSaveRecord before updating the back end from the work table the
form is based on.

It works... sort of....

The rub comes when stepping though code. It throws a "2046: The
command or action 'SaveRecord' isn't available now" - which makes
sense, seein that I'm in a code window and not the form.

Sounds like I'm being sloppy but this is the only way I know.

Is there a more robust way to make sure that values in the fields on
my form are flushed to the work table before I do something that
assumes they are?


I usually use this line of code:

If Me.Dirty Then Me.Dirty = False

That saves the form's data if it has been modified. The only hitch is that,
if there's some reason the record can't be saved, you may get a confusing
error message about not being able to set a property (as opposed to not
being able to save the record, which would be self-explanatory). So you
want to have error-handling in place to trap the error and display a more
meaningful message to the user.
 
K

Krzysztof Pozorek [MVP]

Uzytkownik "PeteCresswell said:
In VBA behind a form, I'm doing a DoCmd.DoMenuItem acFormBar, acFile,
acSaveRecord before updating the back end from the work table the
form is based on.

It works... sort of....

The rub comes when stepping though code. It throws a "2046: The
command or action 'SaveRecord' isn't available now" - which makes
sense, seein that I'm in a code window and not the form.

Sounds like I'm being sloppy but this is the only way I know.

Is there a more robust way to make sure that values in the fields on
my form are flushed to the work table before I do something that
assumes they are?

Use Me.Dirty=False instead.

K.P.
 

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