Force record save in code

G

Guest

Hi

I have a problem on a sub form.

On the subform i have a button that opens a report. Obviously if the user
presses the button without moving onto the next record, the report opens
blank because the sub-form record hasn't saved.

I have tried 2 ways to fix this problem with no success so far.

Firstly on the code for the button i put in docmd.runcommand acCmdSaveRecord.

This didn't work.

Then i tried putting

If me.dirty then

me.dirty = false

End If

Now when i press the button i get the error message

"The setting you entered isn't valid for this property"

The report doesn't open and the database crashed.

Any help would be greatly appreciated.

Thanks

Gillian
 
G

Guest

Hi

Thanks for the reply, i tried what you suggested and i get the error

"The DoMenuItem action was cancelled"

And then the report doesn't open.

Thanks

Gillian
 
R

Rick Brandt

gdonald20 said:
Hi

Thanks for the reply, i tried what you suggested and i get the error

"The DoMenuItem action was cancelled"

And then the report doesn't open.

Never use those old DoMenu commands any more. Those are an ancient
throwback only supported for backward compatibility. Either of your
original methods should be fine.

What all of these errors are telling you is that there is some reason that
your record cannot be saved, not that your invoking the save incorrectly.
This could be caused by lots of reasons. Does the same record save if you
save it without using your print button? Move to another record,
Shift-Enter, close the form?
 
G

Guest

Yes i had thought about there being a problem with possibly required fields
etc, but when i tab along to the next record or move to another form and come
back the record is saved perfectly and then the report invokes correctly.

Thanks
Gillian
 
R

Rick Brandt

gdonald20 said:
Yes i had thought about there being a problem with possibly required
fields etc, but when i tab along to the next record or move to
another form and come back the record is saved perfectly and then the
report invokes correctly.

I thought that any error you would get from acCmdSaveRecord would include
WHY the record cannot be saved. That is one of the downsides to using Dirty
= False (which I prefer). That the error is not very helpful.
 

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