Solved

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

Posted on 2007-11-29
4
146 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

839 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