Solved

Filter main form based on criteria in subform

Posted on 2012-03-19
10
457 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

813 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

8 Experts available now in Live!

Get 1:1 Help Now