Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now