Requery a subform of a subform (1 Viewer)

Bee

Registered User.
Local time
Today, 13:21
Joined
Aug 1, 2006
Messages
487
Hi,

I have tried to Requery a subform of a subform, but I can't get it to work.
I tried this:

Code:
Me.SubForm1.Form.SubForm2.requery

Also:

Code:
Me.SubForm1.SubForm2.requery

And:

Code:
Forms![SubForm1]![SubForm2].Form.Requery

Any help will be very much appreciated.
B
 

rainman89

I cant find the any key..
Local time
Today, 08:21
Joined
Feb 12, 2007
Messages
3,015
check here think you are missing a main form reference
 

boblarson

Smeghead
Local time
Today, 05:21
Joined
Jan 12, 2001
Messages
32,059
I'll try to assist you on this as well.

It should be:
Code:
Me.SubForm1.Form.SubForm2.Form.requery

if on the form you have the code on, and if not it would be

Code:
Forms!YourMainFormNameHere.SubForm1ContainerNameHere.Form.SubForm2ContainerNameHere.Form.Requery

Now, for the explanation, which I actually finally got due to a post by Pat Hartman recently.

1. When you are dealing with subforms, you are actually dealing with two parts - the subform CONTAINER (that which houses the subform on the main form) and the subform itself.

2. The subform and subform container can be named the same, but are not necessarily so. You need to check before writing the code. If they are the same then it simplifies things but it doesn't really matter if it is, or isn't, because you just have to refer to the container.

3. When you are doing things like requerying the subform, you are not really requerying the container, as it doesn't have a requery method, but the subform itself does. So, when you are referring to a property, or method, on the actual subform (not the container), you need to have the subform container name and then .Form. between the container name and the method, or property, so Access knows you want to refer to the form's method or property and not the container's method or property.

Hopefully that helps gel in your mind how that all works. I wish I had received that explanation years ago as it would have saved me many hours of trial and error trying to determine when to use what.
 

Users who are viewing this thread

Top Bottom