Force save on sub form

G

Guest

Hi

I have a problem on a subform. I have a button on the subform that opens a
report when pressed.

If i press the button once i have created a new record the report opens
blank, clearly because the record hasn't saved yet.

I tried putting

docmd.Runcommand accmdSave and
docmd.runcommand accmdSaveRecord

in the onclick events of the button.

In each case i get an error stating "The RunCommand event was canceled"

I really can't understand why it doesn't work on the subform. Any help would
be great appreciated.

Thanks
 
C

Carl Rapson

gdonald20 said:
Hi

I have a problem on a subform. I have a button on the subform that opens a
report when pressed.

If i press the button once i have created a new record the report opens
blank, clearly because the record hasn't saved yet.

I tried putting

docmd.Runcommand accmdSave and
docmd.runcommand accmdSaveRecord

in the onclick events of the button.

In each case i get an error stating "The RunCommand event was canceled"

I really can't understand why it doesn't work on the subform. Any help
would
be great appreciated.

Thanks

Try putting

If Me.Dirty Then Me.Dirty = False

right before the OpenReport call.

Carl Rapson
 
M

Marshall Barton

gdonald20 said:
I have a problem on a subform. I have a button on the subform that opens a
report when pressed.

If i press the button once i have created a new record the report opens
blank, clearly because the record hasn't saved yet.

I tried putting

docmd.Runcommand accmdSave and
docmd.runcommand accmdSaveRecord

in the onclick events of the button.

In each case i get an error stating "The RunCommand event was canceled"

I really can't understand why it doesn't work on the subform. Any help would
be great appreciated.


DoCmd can have trouble figuring out what object you want it
to manipulate. Use this magic incantation instead:

Me.Dirty = False
 
G

Guest

Hi

Thanks but when i try me.dirty = false, i get the error

" The setting you entered isn't vaild for this property."

There is only one required field for a valid record on the subform and it is
filled in before pressing the report button, so i really don't understand why
all of the save methods don't appear to work.

Gillian
 
J

John W. Vinson

If i press the button once i have created a new record the report opens
blank, clearly because the record hasn't saved yet.

Put a line

If Me.Dirty = True Then Me.Dirty = False

in the Click event code of your button, before the line that opens the report.

The acCmdSave saves the *design of the Form*, not the data.

John W. Vinson [MVP]
 
G

Guest

I have tried using the dirty code but i get the following error

The setting you entered isn't vaild for this property.

Gillian
 
J

John W. Vinson

I have tried using the dirty code but i get the following error

The setting you entered isn't vaild for this property.

Odd. Is this an unbound form perhaps? or is its Allow Edits property set to
false? What *is* the recordsource of the form?

John W. Vinson [MVP]
 
M

Marshall Barton

Sounds like what John said, unbound form, nonupdatable
record source table/query or maybe there's a typo in your
real code.
 
G

Guest

It's a bound form, with a query as the recordset.

I don't understand why it doesn't work.

If i fill in the subform then tab onto the next record on the subform, it
triggers a save perfectly as you would expect. Then we you go back to the
previous record and press the report button it open perfectly displaying the
data from that record.

It just seems that i can't force the record to do in code what it
automatically does on creating another new record.

Gillian
 
J

John W. Vinson

It's a bound form, with a query as the recordset.

I don't understand why it doesn't work.

If i fill in the subform then tab onto the next record on the subform, it
triggers a save perfectly as you would expect. Then we you go back to the
previous record and press the report button it open perfectly displaying the
data from that record.

It just seems that i can't force the record to do in code what it
automatically does on creating another new record.

Please copy and paste the actual code in your button's click event to a
message here.

John W. Vinson [MVP]
 
G

Guest

Hi

Thanks for your help, i found out what was stopping the if me.dirty code
from working.

I also had code in the BeforeInsert event of the form.

For some reason this code intereferred with the save.

I took it out and then the save worked properly.

Could you tell me why the beforeinsert caused the problem?

Thanks
 
C

Cindy

The button to print the report is probably on the main form, not the
subreport, and therefore the dirty command isn't making it to the
subform.

What if you try moving the if me.dirty code to the on exit of the
subform object itself? (or maybe in the text boxes that get edited on
the subform??)

Cindy
 
G

Guest

Hi

Thanks for your help but i managed to fix the problem.

The button is on my subform, but what was stopping the code working was a
BeforeUpdate event.

Thanks

Gillian
 
J

John W. Vinson

The button is on my subform, but what was stopping the code working was a
BeforeUpdate event.

BeforeUpdate or BeforeInsert???? You've said both.

John W. Vinson [MVP]
 
G

Guest

Sorry wasn't paying enough attention to what i was writing.

The event that seemed to cause the save to fail was in the BeforeInset event.

I removed it as on reflection it wasn't in the best place anyway, but as
soon as i did the save worked using the "dirty" code.

I put it back just to satisfy my curiousity and low and behold the save code
then failed again.

Thanks

Gillian
 
J

John W. Vinson

I put it back just to satisfy my curiousity and low and behold the save code
then failed again.

Evidently there was something wrong with the code.

Obviously nobody here can help you figure out what, since you've chosen to
keep us in the dark.

John W. Vinson [MVP]
 
G

Guest

I'm sorry you felt i was keeping you in the dark.

All the code did was run an append query and not to be rude there was
nothing wrong with it. I have moved it to another event an it works perfectly
without interferring with the save.

Last night i googled this problem and found that many people had experienced
save problems if there is code in either the BeforeInsert or BeforeUpdate
events.

Thanks
 
J

John W. Vinson

I'm sorry you felt i was keeping you in the dark.

Sorry... I misunderstood. It sounded like you were still wondering why the
code was causing the problem, and were asking for help. Evidently I was
mistaken.
Last night i googled this problem and found that many people had experienced
save problems if there is code in either the BeforeInsert or BeforeUpdate
events.

You can certainly get into a loop; if either of these events changes the value
that will be saved, it will cause the event to be fired again.

John W. Vinson [MVP]
 

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

Similar Threads


Top