• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Need help dynamically filtering subforms so I can re-use them.

Probably easy for an Access Whiz, but I just don't get it.

I wish to use the SAME subform twice on a main form, but wish the results they display to be different. I want to do this so I do not have to design two subforms which are identical apart from the results they display.

For example, [subform1] will show items from my orders table that are ordered, [subform2] will show items from my orders table that are not ordered. The "Source Object" for both of these forms are set to the same: [frmPurchaseOrderListSubform]

How do I achieve this?


0
AbacusInfoTech
Asked:
AbacusInfoTech
  • 2
  • 2
1 Solution
 
peter57rCommented:
Assuming you have added the subform twice to your main form, you need to know the names of the container control for each subform (in the code below the orderdetails subform is added into Child20 and Child30.

Then you can do something like:

Private Sub Command32_Click()
Dim str1
Dim str2
str1 = "SELECT Orderdetails.* FROM Orderdetails WHERE Orderdetails.ProductID>20;"
str2 = "SELECT Orderdetails.* FROM Orderdetails WHERE Orderdetails.ProductID<=20;"

Me.Child20.Form.RecordSource = str1
Me.Child30.Form.RecordSource = str2

End Sub
0
 
AbacusInfoTechAuthor Commented:
In the onOpen of the main form I guess? I'll give it a go.
0
 
peter57rCommented:
I should add that as far as I know you have to do the recordsource settings via code.  I don't believe there is any way to do it via the UI.
0
 
AbacusInfoTechAuthor Commented:
Yep, exactly what I needed. Thanks...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now