Solved

Filter main form based on criteria in subform

Posted on 2012-03-19
10
439 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
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
Comment Utility
<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
Comment Utility
Yeah ;-)
0
 

Accepted Solution

by:
jaguar5554 earned 0 total points
Comment Utility
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
Comment Utility
The solution was provided by AllenBrown (from his website) and did exactly what I needed the filter to do.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

762 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

13 Experts available now in Live!

Get 1:1 Help Now