Solved

Filter main form based on criteria in subform

Posted on 2012-03-19
10
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

687 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