Saving a Parent form when Subform has focus

J

Jen S

I'm in process of converting someone else's database from Access 97 to
Access 2003. Some of the code is kludgy, but I don't have a lot of time to
accomplish this, so I'm trying to avoid major redesigns of form
functionality if at all possible. But I've just run into my first weird
thing that works fine in 97 and fails in 2003. Any suggestions would be
appreciated!

I have a Parent/Subform setup. There is code in the Subform_Enter event on
the parent that does a quick update of the parent form and does a
"RunCommand acCmdSaveRecord". In Access97, this saved the parent record,
ensuring that some vital referential integrity info. was in place when the
subform went to save its own data.

In Access 2003, the record is not updating...just staying dirty. My best
guess is that focus has already shifted to the subform when I call the
runcommand, and so it's "saving" the subform record (which doesn't exist
yet) instead of the parent.

Is there some other way to force the Parent form to save from within a
subform?

TIA!
Jen
 
G

Graham Mandeno

Hi Jen

You can ensure the correct form is being saved by setting its Dirty property
to False:
Forms![Your Main form].Dirty = False

or, from the main form's class module:
Me.Dirty = False

or, from the subform's class module:
Me.Parent.Dirty = False

However, there is more to this than meets the eye, because changing focus
from the main form to a subform should trigger an automatic save of the main
form record. How is the main form then becoming dirty again?
 
R

Rick Brandt

Jen said:
I'm in process of converting someone else's database from Access 97 to
Access 2003. Some of the code is kludgy, but I don't have a lot of
time to accomplish this, so I'm trying to avoid major redesigns of
form functionality if at all possible. But I've just run into my
first weird thing that works fine in 97 and fails in 2003. Any
suggestions would be appreciated!

I have a Parent/Subform setup. There is code in the Subform_Enter
event on the parent that does a quick update of the parent form and
does a "RunCommand acCmdSaveRecord". In Access97, this saved the
parent record, ensuring that some vital referential integrity info.
was in place when the subform went to save its own data.

In Access 2003, the record is not updating...just staying dirty. My
best guess is that focus has already shifted to the subform when I
call the runcommand, and so it's "saving" the subform record (which
doesn't exist yet) instead of the parent.

Is there some other way to force the Parent form to save from within a
subform?

The code is unnecessary as Access will always save the parent record when
you move focus to the sub. It will also automatically save the subform
record when you move focus to the parent (or a different subform). Not only
is this automatic, but there is no way to prevent it even if you wanted to.
 
J

Jen S

Graham Mandeno said:
However, there is more to this than meets the eye, because changing focus
from the main form to a subform should trigger an automatic save of the
main form record. How is the main form then becoming dirty again?

The code in Subform_Enter updates the value in a field on Parent, which
dirties up the form. I assume that the auto-save occurs before the subform
enter event fires...

Thanks for the info on the Dirty property. I'd never thought to try
actually SETTING that value before. :)

Jen
 

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