Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-29
4
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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