Syntax to refresh subform

J

Jack Sheet

What is the syntax, please, to insert into the
Private Sub Form_Current()
event of a parent form
in order to refresh a subform contained within that parent form?
I have a subform called "F_TJA_Tasks_Sub" and I have tried the following
combinations:
F_TJA_Tasks_Sub.Form.Refresh (does not compile - variable not defined)
Forms("F_TJA_Tasks_Sub").Refresh - run time error 2450 form not found
Forms("F_TJA_Tasks_Sub").Form.Refresh - run time error as above
Forms![F_TJA_Tasks_Sub].Refresh - run time error as above.
 
J

John Spencer

I would try

Me.F_TJA_Tasks_Sub.Form.Refresh
or perhaps
Me.F_TJA_Tasks_Sub.Form.Requery

But is "F_TJA_Tasks_Sub" the name of the subform control or is it the name
of the form that is contained in the subform control. The names can be the
same, but the names can be different.

Subforms are not part of the FORMS collection so your other methods are
going to fail.
 
S

Steve Schapel

Jack,

I think this should do it...
Me.F_TJA_Tasks_Sub.Form.Refresh
.... but this assumes that F_TJA_Tasks_Sub is the name of the *subform
control* on the main form, as distinct from the name of the form you are
using for the subform. In practice, these are often the same, but not
necessarily so. Check the name of the subform control by selecting it
in the design view of the main form, and look at the properties.

The other question is why you want to do this. The Current event of the
main form implies moving to another record on the main form, and I can't
really imagine a circumstance where a Refresh of a subform would be
applicable at this time.
 
J

Jack Sheet

Outstanding.
Thank you thank you

I was referring to the control source instead of control name. All works
fine now.

John Spencer said:
I would try

Me.F_TJA_Tasks_Sub.Form.Refresh
or perhaps
Me.F_TJA_Tasks_Sub.Form.Requery

But is "F_TJA_Tasks_Sub" the name of the subform control or is it the name
of the form that is contained in the subform control. The names can be
the same, but the names can be different.

Subforms are not part of the FORMS collection so your other methods are
going to fail.


Jack Sheet said:
What is the syntax, please, to insert into the
Private Sub Form_Current()
event of a parent form
in order to refresh a subform contained within that parent form?
I have a subform called "F_TJA_Tasks_Sub" and I have tried the following
combinations:
F_TJA_Tasks_Sub.Form.Refresh (does not compile - variable not defined)
Forms("F_TJA_Tasks_Sub").Refresh - run time error 2450 form not found
Forms("F_TJA_Tasks_Sub").Form.Refresh - run time error as above
Forms![F_TJA_Tasks_Sub].Refresh - run time error as above.
 
J

Jack Sheet

Outstanding. Thank you thank you.
I had been referring to the control source rather than control name.

As to your final paragraph, I was experimenting with a possible solution to
a problem that I mentioned in another thread.
The problem was that the subform contains a combo box that selects filtered
records depending on controls in the parent form. The drop down list in
that combo box was not refreshing properly when I changed records in the
main form. Forcing the refresh does now appear to work.

Steve Schapel said:
Jack,

I think this should do it...
Me.F_TJA_Tasks_Sub.Form.Refresh
... but this assumes that F_TJA_Tasks_Sub is the name of the *subform
control* on the main form, as distinct from the name of the form you are
using for the subform. In practice, these are often the same, but not
necessarily so. Check the name of the subform control by selecting it in
the design view of the main form, and look at the properties.

The other question is why you want to do this. The Current event of the
main form implies moving to another record on the main form, and I can't
really imagine a circumstance where a Refresh of a subform would be
applicable at this time.

--
Steve Schapel, Microsoft Access MVP


Jack said:
What is the syntax, please, to insert into the
Private Sub Form_Current()
event of a parent form
in order to refresh a subform contained within that parent form?
I have a subform called "F_TJA_Tasks_Sub" and I have tried the following
combinations:
F_TJA_Tasks_Sub.Form.Refresh (does not compile - variable not defined)
Forms("F_TJA_Tasks_Sub").Refresh - run time error 2450 form not found
Forms("F_TJA_Tasks_Sub").Form.Refresh - run time error as above
Forms![F_TJA_Tasks_Sub].Refresh - run time error as above.
 
S

Steve Schapel

Ok, now I understand, Jack.

I would not normally think of doing this with a Refresh of the subform.
I would take either of these approaches...

On the Current event of the main form...
Me.NameOfSubform.Form!NameOfCombobox.Requery

or, more likely, on the Enter event of the combobox...
Me.NameOfCombobox.Requery
 
J

Jack Sheet

Thanks
Just out of interest, and to increase my understanding, not that I would
actually do it, but:

If I were to do several approaches in the same database, is there an order
of priority in which the computer will undertake the instructions?

ie, would it run the Enter event on the combo box in the subform before
running the On Current event on the main form?
 
S

Steve Schapel

Jack,

Yes, there is a definite order in which events are processed. Not
necessarily an order of priority, but a chronological order. The
example you used is not a good one, as the Enter event of the combobox
will only occur when the combobox is accessed, normally by clicking or
tabbing. So it could be that the Current event of the main form will
occur, but the Enter event of the combobox will not even happen. But
then, if you're not going to be actively using the combobox, it doesn't
matter that the code to requery the row source does not occur. But if
you had the code on both events, then it would run twice.
 

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