Solved

Filter main form based on criteria in subform

Posted on 2012-03-19
10
466 Views
Last Modified: 2012-08-14
Hello~ can anyone help me with filtering a main form based on a value that's in a subform. The main form and subform are linked by a key identifier from the main form. My database does not have a join table. Any help is greatly appreciated. Thank you in advance.
0
Comment
Question by:jaguar5554
  • 4
  • 3
  • 3
10 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 37739364
We need a bit more info.  The main form is based on some table.  What is the subform based on - another Table?  If so the Master and Child fields of the subform must be filled in with the appropriate field names from both tables, each containing the key identifier.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739375
You can do anything you want....
But filtering the main form from a record in the subform is inherently Backwards...

A Main form (Customers) will filter the records in a subform (Orders)
...Not the other way around.

So you will have to be very detailed in describing your design here, and the need for this...

If you want to do something like this, you will need and entirely Different/New "Form".
This new form will be based on the subform records only.
Then you can simply apply a filter for the "Main" form records)

Create the "Form" based on the Child table. (ex.: Orders)
Create a combobox on the form to list the "Parent" records (Customers)

Then on the after Update event of the combobox (or on a "Apply Filter" Button)
Do something like this:
Me.Filter="CustomerID=" & me.cboCustomerID    'For a Numeric Key
'Or this for a text key:
'Me.Filter="CustomerID=" & "'" & me.cboCustomerID & "'"
Me.FilterOn=True

Then you can reset the filter (show all) with something like this:
'Me.Filter=""
Me.FilterOn=False

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739382
correction:

This:
Then you can reset the filter (show all) with something like this:
'Me.Filter=""
Me.FilterOn=False

...Should be:
Then you can reset the filter (show all) with something like this:
Me.Filter=""
Me.FilterOn=False
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 44

Expert Comment

by:GRayL
ID: 37739434
Jeff, I haven't been doing much with Access for the past month but shouldn't those two lines be reversed?  When you create the filter, you create the text component, then turn the filter on.  I would have thought you should reverse the process - turn it off, then make the filter a zero length string.
0
 

Author Comment

by:jaguar5554
ID: 37739569
Hello boag2000~ you bring up a concept I did not think of before -- a different form completely. Let me try that and if it does not work, I will update my question with my database and current form setup. Stay tuned....
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739688
GRayL,

To be honest, I am sure it would work either way...
So perhaps your syntax would be more elegant...

I just have always done it this way.
(I always do the filtering and clearing the filter via a button, ...if that matters

But trust me, I have been know to have been doing things wrong for years...
LOL

;-)


Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739709
<Hello boag2000~ you bring up a concept I did not think of before -- a different form completely.>
Again, what you asked for originally was a bit odd...

If you Selected a Customer on the main form (Customer 101), ...the subform would Only show records (ex. Orders) for Customer101.
...So how would the subform show any other main record than Cust101, for you to filter on?
0
 
LVL 44

Expert Comment

by:GRayL
ID: 37740337
Yeah ;-)
0
 

Accepted Solution

by:
jaguar5554 earned 0 total points
ID: 37758330
Applied the following on the AfterUpdate event:
Dim strSQL As String
If IsNull(Me.Combo73) Then
    ' If the combo is Null, use the whole table as the RecordSource.
    Me.RecordSource = "tblMaster"
Else
    strSQL = "SELECT DISTINCTROW tblMaster.* FROM tblMaster " & _
        "INNER JOIN rtblAttributes ON " & _
        "tblMaster.MasterID = rtblAttributes.MasterID " & _
        "WHERE rtblAttributes.Attribute = " & Chr(34) & Me.Combo73 & Chr(34) & ";"    'for text value
    Me.RecordSource = strSQL

End If
0
 

Author Closing Comment

by:jaguar5554
ID: 37775706
The solution was provided by AllenBrown (from his website) and did exactly what I needed the filter to do.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

808 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