Requery Subforms

C

Combustible Kid

I have a list box on a main form. When the list box is updated it should
requery within per the after update procedure two subforms [sfrmAgency] and
[sfrmEmployment].

The after update procedure is returning an error stating that it "can't find
the field 'sfrmAgency'...", however [sfrmEmployment] had been working okay.
Unfortunately, I accidently deleted it. When it was recreated I got the same
behavior. The same thing happens on my OnCurrent procedure for the main form.

The afterupdate procedure is:
[Forms]![frmPerson]![sfrmEmployment].Requery
[Forms]![frmPerson]![sfrmAgency].Requery

I have also tried:
[Forms]![frmPerson].[sfrmEmployment].[Form].Requery
[Forms]![frmPerson].[sfrmAgency].[Form].Requery
 
K

Klatuu

Addressing subforms takes another level of object reference. As written,
this version trying to requery the subform control on the main form.

[Forms]![frmPerson]![sfrmEmployment].Requery
[Forms]![frmPerson]![sfrmAgency].Requery

But, my guess is sfrmEmployment and sfrmAgency are not the names of subform
controls on frmPerson, but the names of the forms being used as a subform.

This version is closer, but again I think you are using the name of the forms.

[Forms]![frmPerson].[sfrmEmployment].[Form].Requery
[Forms]![frmPerson].[sfrmAgency].[Form].Requery

The correct refernce is to use the name of the subform control, not the name
of the form. The main form knows nothing about the forms being used as
subforms. It only knows about the subform controls. A subform control has a
Source Object property. That is what defines the form to use as the subform.
Then you have to use the Form reference because it is what identifies the
refence to the form being used as a subform. So, the short of it is, change
the names to use the control name, not the form name. If the subform is on
the main form where your code is, all you need is:

Me.SubFormControlName.Form.Requery
 

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