Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-29
4
Medium Priority
?
155 Views
Last Modified: 2013-11-28
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
Comment
Question by:AbacusInfoTech
  • 2
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 20375138
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
 
LVL 1

Author Comment

by:AbacusInfoTech
ID: 20375146
In the onOpen of the main form I guess? I'll give it a go.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 20375152
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
 
LVL 1

Author Comment

by:AbacusInfoTech
ID: 20376364
Yep, exactly what I needed. Thanks...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question