Save Parent Record Before Moving to Subform

A

Alan Z. Scharf

1. I have parent form showing one record at a time, and a detail subform in
datasheet view. The two forms are linked by ContactID.

2. If I move to subform before saving changes made in parent form, the
parent form apparently requeries and goes back o the first alphabetical Last
name. Underlying parent form query is sorted by LastName, FirstName.

3. If I save changes in parent form before going to subform, this does not
happen.

4. If I call my save routine after each field's On Exit event, form saves
when I leave any field and move to subform.
However, I don't want to save after exiting each field, only when leave
parent form.

4. How can I save record when the cursor leaves the parent form and touches
the subform. I tried using the parent Form's LostFocus, OnDirty, and
DeActivate events, but that doesn't work. No error messages, just doesn't
save.

Thanks for any help.

Alan
 
G

Graham Mandeno

Hi Alan

The current record in the parent form is *always* saved when the subform
gets the focus. This happens automatically and, in fact, the subform
*cannot* receive the focus unless the parent record can be successfully
saved.

Therefore, the problem must be in some code that is executing when the
parent record is saved. Check your code to ensure that you are not
requerying the main form anywhere, either explicitly, or implicitly, for
example by changing a filter. It might help to set a breakppoint in the
parent form's BeforeUpdate event procedure and single-step through the code
from there.
 
A

Alan Z. Scharf

Graham,

Thanks very much.

It was the automatic save that was doing the requery.

I solved the problem with your suggestion about looking in BeforeUpdate, and
putting varBookmark = Me.Bookmark there.

Then put Me.Bookmark = varBookmark in AfterUpdate.

Regards,

Alan

I put varBookmark = Me.Bookmark in BeforeUpdate,
Graham Mandeno said:
Hi Alan

The current record in the parent form is *always* saved when the subform
gets the focus. This happens automatically and, in fact, the subform
*cannot* receive the focus unless the parent record can be successfully
saved.

Therefore, the problem must be in some code that is executing when the
parent record is saved. Check your code to ensure that you are not
requerying the main form anywhere, either explicitly, or implicitly, for
example by changing a filter. It might help to set a breakppoint in the
parent form's BeforeUpdate event procedure and single-step through the code
from there.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Alan Z. Scharf said:
1. I have parent form showing one record at a time, and a detail subform
in
datasheet view. The two forms are linked by ContactID.

2. If I move to subform before saving changes made in parent form, the
parent form apparently requeries and goes back o the first alphabetical
Last
name. Underlying parent form query is sorted by LastName, FirstName.

3. If I save changes in parent form before going to subform, this does
not
happen.

4. If I call my save routine after each field's On Exit event, form saves
when I leave any field and move to subform.
However, I don't want to save after exiting each field, only when leave
parent form.

4. How can I save record when the cursor leaves the parent form and
touches
the subform. I tried using the parent Form's LostFocus, OnDirty, and
DeActivate events, but that doesn't work. No error messages, just doesn't
save.

Thanks for any help.

Alan
 

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