Requery form on tab ctrl after adding record

T

Tina Hudson

Good day,

I have a form "frmMainFamily" with 6 pages (tab ctrls), connected by a field
"Family_ID". On each tab ctrl, I have a subform, with a cmd button on each
subform that, when clicked on, opens a form to add records to that subform.

The subform does not close, and the add form appears on top.

For 4 of the 6 sub forms, the newly added record appears automatically,
after I close the add form. For the last 2 tab ctrls, it does not. I have
to exit the form and then reopen the form to see the new record.

On the add form, I have a cmd button a user clicks to save record (cmdOK),
for each of the 6 forms, as follows:

DoCmd.OpenForm "frmMainFamily", acNormal, "",
"[Family_ID]=[Forms]![frmQuickAdd_TDM]![Family_ID]", , acNormal

DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes

Note that the add forms (frmQuickAdd) all have unique names, but I return
the user to basically where they were before.

I do have additional code before this where it checks to make sure that the
user has filled in required fields, such as a date. But this doesn't seem to
matter when I test it.

Any help will be most appreciated.
 
J

John Spencer

First of all the line
DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes
closes the form and saves changes to the structure of the form. No harm in
that, but I suspect that you thought that acSaveYes was causing the data to
be saved. Closing the form should do that.

You might add a line to the code that requeries the subform on frmMainFamily
to force the update. I suspect that the subforms that are not updating may
not be linked to the FamilyID value, but that could be way off.

Try adding something like the following
Forms!frmMainFamily!NameOfSubFormControl.Requery
Or the line may need to read
Forms!frmMainFamily!NameOfSubFormControl.Form.Requery
after your
DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
T

Tina Hudson

John,

I have actually tried doing that code, sorry I didn't mention it, and I
couldn't get it to work. I tried requering the main form and then the sub
form. I also tried DoCmd.Requery (I'm using Access 2000, maybe I shouldn't
have left that out), which didn't work either.

I guess my confusion is why is it working with some of the sub forms, but
not all. The code is the same for opening the add form and saving the
record, so it should work the same. I do realize that when the form closes
it saves the record, but I must be anal or something, cuz why would MIcrosoft
have acsaveyes, if it wasn't needed? Is it perhaps to save the form, and not
necessarily the record? Anyway, I still can't get it to work.

Any other possible suggestions?

--
Thanks,
Tina Hudson


John Spencer said:
First of all the line
DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes
closes the form and saves changes to the structure of the form. No harm in
that, but I suspect that you thought that acSaveYes was causing the data to
be saved. Closing the form should do that.

You might add a line to the code that requeries the subform on frmMainFamily
to force the update. I suspect that the subforms that are not updating may
not be linked to the FamilyID value, but that could be way off.

Try adding something like the following
Forms!frmMainFamily!NameOfSubFormControl.Requery
Or the line may need to read
Forms!frmMainFamily!NameOfSubFormControl.Form.Requery
after your
DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Tina Hudson said:
Good day,

I have a form "frmMainFamily" with 6 pages (tab ctrls), connected by a
field
"Family_ID". On each tab ctrl, I have a subform, with a cmd button on
each
subform that, when clicked on, opens a form to add records to that
subform.

The subform does not close, and the add form appears on top.

For 4 of the 6 sub forms, the newly added record appears automatically,
after I close the add form. For the last 2 tab ctrls, it does not. I
have
to exit the form and then reopen the form to see the new record.

On the add form, I have a cmd button a user clicks to save record (cmdOK),
for each of the 6 forms, as follows:

DoCmd.OpenForm "frmMainFamily", acNormal, "",
"[Family_ID]=[Forms]![frmQuickAdd_TDM]![Family_ID]", , acNormal

DoCmd.Close acForm, "frmQuickAdd_TDM", acSaveYes

Note that the add forms (frmQuickAdd) all have unique names, but I return
the user to basically where they were before.

I do have additional code before this where it checks to make sure that
the
user has filled in required fields, such as a date. But this doesn't seem
to
matter when I test it.

Any help will be most appreciated.
 

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