Filter subform from another subform (within a navigation form of a main form) (1 Viewer)

emad981

Registered User.
Local time
Today, 02:44
Joined
Aug 20, 2013
Messages
17
I have an unbounded Form Called [frmTestsMain] which includes 3 subforms:

  1. [frmTestsList]
  2. [frmTMGroupList]
  3. [frmTSGroupList]

  • [frmTMGroup] has a filed "TMGroup",
  • [frmTSGroup] has a filed called "TSGroup" and another lookup filed "TMGroup" linked to [frmTMGroup].TMGroup.
  • [frmTestsList] has lookup filed "TSGroup" linked to [frmTSGroup].TSGroup.
What I want is:

  1. When I click [frmTMGroup].TMGroup, the other subform [frmTSGroup] to be filtered to get only TMGroup clicked.
  2. When I click [frmTSGroup].TSGroup, the other subform [frmTestsList] to be filtered to get only TSGroup clicked.
I wrote the code like below and worked with no problems If I open the [frmTestsMain] directly.

Code:
Private Sub TestMGroup_Click() 
Forms![frmTestsMain]![frmTSGroupList].Form.Filter = "TestMGroup =" & Me.ID  
Forms![frmTestsMain]![frmTSGroupList].Form.FilterOn = True   
End Sub
and

Code:
Private Sub TestSGroup_Click()  
Forms![frmTestsMain]![frmTestsList].Form.Filter = "TestSGroup =" & Me.ID 
 Forms![frmTestsMain]![frmTestsList].Form.FilterOn = True  
End Sub
But when I included the [frmTestsMain] from in A navigation form with a min from , i get an error.

I tried to modify the code like the following but I get the same problem

Code:
Private Sub TestMGroup_Click() 
Forms![frmMain]![NaviTests]![frmTestsMain]![frmTSGroupList].Form.Filter = "TestMGroup =" & Me.ID
Forms![frmMain]![NaviTests]![frmTestsMain]![frmTSGroupList].Form.FilterOn = True 
  End Sub
Could you help me please. Thanks
 

sneuberg

AWF VIP
Local time
Yesterday, 16:44
Joined
Oct 17, 2014
Messages
3,506
When you create a Navigation form and put your form in a tab your form ends up in a subform name NavigationSubform. If you didn't change that name but named the Navigation form "frmMain" then the reference for the Filter would be:

Code:
[Forms]![frmMain]![NavigationSubform].[Form]![frmTSGroupList].[Form].Filter

If you changed the subform name to NaviTests then

Code:
[Forms]![frmMain]![NaviTests].[Form]![frmTSGroupList].[Form].Filter

I use http://access.mvps.org/access/forms/frm0031.htm for this sort of thing.
 
Last edited:

sneuberg

AWF VIP
Local time
Yesterday, 16:44
Joined
Oct 17, 2014
Messages
3,506
You can use the Query Builder to help you form a reference. To do this first open ALL of the forms involved in the reference even if they are open as a subform in some main form. In your case for example you should have four forms open. Then on the CREATE Tab click Query Design. You can just close the Show Table dialog as we don't need a table. In the grid below type forms! in any of the Criteria. You should see all of your forms in the drop down. If you don't then close everything restart Access and start over again. But assuming you see the forms select the top most form in the reference you want. In your case that would be frmMain, the navigation form.

At this point if you type a period (.) after forms![frmMain] you will see the properties of frmMain like its Record Source. You don't want that so type a exclamation point (!) to see what in the form's collection. One of the things in this forms collection is a subform. Assuming you named the navigation subform NaviTests you will see that. Select that so at this point you have

Code:
[forms]![frmMain]![NaviTests]

If you type a exclamation point (!) after this you won't see anything as subforms are controls and not collections. If you type a period (.) after it you will see the properties of the subform. The one you are interested in is Form so select that. You now should have.
Code:
[forms]![frmMain]![NaviTests].[Form]

What you now have is a reference to the form which was contained in the subform NaviTests; namely in your case frmTestMain. Again typing a period after this will show the properties of the form and and exclamation point will show what's in the forms collection. You want to get to the subform so type an exclamation point. You should see both the frmTMGroupList and frmTSGroupList subforms. Let choose frmTSGroupList you should now have
Code:
[forms]![frmMain]![NaviTests].[Form]![frmTSGroupList]

Add a .Form to this will give you a reference to the frmTSGroupList form. You should have
Code:
[forms]![frmMain]![NaviTests].[Form]![frmTSGroupList].[Form]

Please note that at this point if you don't have the frmTSGroupList form open the form icon will be green and IntelliSense will not help you further in developing the reference. Anyway this is both a collection and has properties so if you type a exclamation point after it you should see the control TSGroup for example. If you want a property like Filter then type a period. You now should have
Code:
[forms]![frmMain]![NaviTests].[Form]![frmTSGroupList].[Form].[Filter]

which you can feel more confident in as the IntelliSense confirmed it.

So just copy and paste it to your code and close the query.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:44
Joined
May 7, 2009
Messages
19,229
Code:
Private Sub TestSGroup_Click()  
Forms![[COLOR=Blue]NavigationFormName[/COLOR]]![[COLOR=Blue]NavigationSubForm[/COLOR]].Form![frmTestsList].Form.Filter = "TestSGroup =" & Me.ID 
Forms![[COLOR=Blue]NavigationFormName[/COLOR]]![[COLOR=Blue]NavigationSubForm[/COLOR]].Form![frmTestsList].Form.FilterOn = True  
End Sub

Private Sub TestMGroup_Click() 
Forms![[COLOR=Blue]NavigationFormName[/COLOR]]![[COLOR=Blue]NavigationSubForm[/COLOR]].Form![frmTSGroupList].Form.Filter = "TestMGroup =" & Me.ID
Forms![[COLOR=Blue]NavigationFormName[/COLOR]]![[COLOR=Blue]NavigationSubForm[/COLOR]].Form![frmTSGroupList].Form.FilterOn = True 
End Sub
 

emad981

Registered User.
Local time
Today, 02:44
Joined
Aug 20, 2013
Messages
17
Thanks for all of you for your answers , unfortunately, tried all of them with no luck. the problem still exists.:banghead:

this is the error message:
Run-Time Error 2450
Microsoft access can't find the referenced form "frmTestsMain"
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:44
Joined
May 7, 2009
Messages
19,229
you do not need the name "frmTestMain"
you only need the name of your Navigation Form (Main Form) and the NavigationSubform name (default is NavigationSubform if you did not rename it).

did you see my code. you replaced the blue colored with correct name of Navigation Form and NavigationSubform.
 

emad981

Registered User.
Local time
Today, 02:44
Joined
Aug 20, 2013
Messages
17
Sorry Again, It was my mistake, I followed your tutorials again carefully and it worked like charm
Code:
Private Sub TestMGroup_Click()
Forms![frmMain]![NavigationSubform].Form![frmTSGroupList].Form.Filter = "TestMGroup =" & Me.ID
Forms![frmMain]![NavigationSubform].Form![frmTSGroupList].Form.FilterOn = True
End Sub

Thanks again
 

Users who are viewing this thread

Top Bottom