473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Filter 1st subform based on 2nd subform

BHo15
143 128KB
I have a parent form (just a shell) with a subform, that contains its own subform with related records. I would like to be able to search for records in the 2nd subform (through a recordset), and then when found, have both the 2nd subform, and the 1st subform filter.

I tried using Set RS = Me.1stSub.Form.2ndSub.Form.Recordsetclone, and I got error 2455 (invalid reference to the property Form/Report). I also tried Set RS = Me.1stSub.2ndSub.Form.Recordsetclone, and this did not work either (although not error 2455).

So...Question #1: How to I build a recordset to that 2nd subform? And Question #2: Any ideas how to make that 1st subform also filter once I have filtered the 1st subform?
Mar 14 '18 #1
7 2535
twinnyfo
3,653 Expert Mod 2GB
BHo15,

First, it's not "exactly" clear what you are trying to do. Let me try to summarize:

You have a Form. On this Form is a Subform. On that SubForm, you have another SubForm. I think I have that correct?

Here is my question: If you are searching records on that second SubForm, why do you need to filter it by the record you have found? Some further clarificaiton would be appreciated.

However, concerning your questions:

Question #1: How to I build a recordset to that 2nd subform?
If you are currently working on that second subform Me.RecordsetClone should work. If you are working on another Form, the best way is to use explicit references: Forms!MainForm.1stSub.Form.2ndSub.Form.Recordsetcl one. You can research details in this article on Referencing SubForms.

Question #2: Any ideas how to make that 1st subform also filter once I have filtered the 1st subform?
The answer to this is similar to the first. Once you determine your Filter Parameters, you can assign that filter by referencing that Form explicitly.

So, even though you have two questions, they are similar enough in nature that they canboth be answered on this same thread.

Hope this hepps!
Mar 14 '18 #2
BHo15
143 128KB
First of all, let me say that I am honored to have you answering my question twinnyfo. I was spending a lot of time on Bytes many years back, and always appreciated your work. And no...I'm not brown nosing. :)

Regarding your uncertainties... You have a Form. On this Form is a Subform. On that SubForm, you have another SubForm. I think I have that correct?

Here is my question: If you are searching records on that second SubForm, why do you need to filter it by the record you have found? Some further clarificaiton would be appreciated.


Yes on the first question. Parent form (just a shell with some buttons and combo boxes). Subform 1 contains data on tasks that are in progress. These tasks are called Actions. Subform 2 contains data on progress for those tasks. The progress notes are called Responses. So… Subform 1: Actions. Subform 2: Responses. This is a one to many relationship.

We have it working to search for a word in the Actions subform, and have the subform filter to only those actions that have that word in them. But the desire is to also look through the Responses subform. If that word is seen in any of the responses, then we would like the responses subform to filter, and then subsequently, the Actions subform would filter to only those actions that contain the filtered responses. Make sense?

I will try your set-up of the recordset next time I can get back to the database, and will let you know.
Mar 14 '18 #3
twinnyfo
3,653 Expert Mod 2GB
Before I move too far ahead of myself, I want to clarify a few things. One has to do with structure, the other has to do with "possibilities."

Structure (Table/Field names are assumed)

Expand|Select|Wrap|Line Numbers
  1. tblActions
  2. ActionID  Action       Action Detail
  3. 1         Sweep Floor  Run the broom back and forth
  4. 2         Mop Floor    Run the mop back and forth
  5. 3         Kick Back    Do nothing
  6. 4         Go Fishing   Catch some bass
Expand|Select|Wrap|Line Numbers
  1. tblResponses
  2. ResponseID  ActionID  Response
  3. 1           1         Sweep faster
  4. 2           1         Get the corners
  5. 3           2         Great job
  6. 4           2         Don't slip!
  7. 5           3         Your moving too fast
  8. 6           3         Slow day on the job
  9. 7           4         Get a faster boat
  10. 8           4         Call it a day
In general, this is correct?

Then, on fsubActions there is a Text Box; someone enters a search item. The code searches through tblActions for this search word and filters only those records which contain that search word. If your subforms are built correctly, this "should" automatically filter fsubResponses properly.

This is all correct?

But the desire is to also look through the Responses subform. If that word is seen in any of the responses, then we would like the responses subform to filter, and then subsequently, the Actions subform would filter to only those actions that contain the filtered responses.
This is about possibilities.

A. When you enter the search word, do you want fsubActions to filter only those records with the search word, and then, based upon that filtered set of records, filter only those records in fsubResponses which also contain that search word?

OR

B. When you enter the search word, you want to filter only those records in fsubResponses which contain that search word and subsequently filter fsubActions based upon that set of records in fsubResponses?

Examples for A:
Search Word: "the"
fsubActions filters IDs 1 and 2; fsubResponses filters ID 2

Search Word: "do"
fsubActions filters ID 3; fsubResponses filters nothing

Search Word: "ing"
fsubActions filters ID 3; fsubResponses filters ID 5


Examples for B:
Search Word: "fast"
fsubResponses filters IDs 1, 5 and 7; fsubActions filters IDs 1, 3 and 4

Search Word: "job"
fsubResponses filters IDs 3 and 6; fsubActions filters IDs 2 and 3

Search Word: "day"
fsubResponses filters IDs 6 and 8; fsubActions filters IDs 3 and 4

Or, is there some other permutation that you are looking for?

I think this might be pretty straightforward, but I need to be sure of these things first.
Mar 15 '18 #4
BHo15
143 128KB
Good stuff twinnyfo. Here are my thoughts.

1) Your setup of structure was correct, with the exception of the search text box... This is on the parent form, not either of the subforms. And yes... When the Actions subform is filtered, the Responses subform is also filtered.
2) Your break down of Possibility A and B brought up some good thoughts. Initially I had in mind that Actions would be filtered first, and then it would look at Responses. This would be overkill, and likely counterproductive. Therefore, what I am thinking now, is there will be an option group beside the search box asking whether you wanted to search Actions or Responses.
3) So, since Actions is good, let's focus on searching Responses. So that would be B, and your description and examples were correct.
Mar 15 '18 #5
twinnyfo
3,653 Expert Mod 2GB
Assuming an Option Group in which "1" searches the Responses:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2. On Error GoTo EH
  3.     Dim strSQL As String
  4.  
  5.     If optSearch = 1 Then
  6.         strFilter = "ActionID IN (" & _
  7.             "SELECT ActionID " & _
  8.             "FROM tblResponses " & _
  9.             "WHERE Response Like '*" & Me.txtSearch & "*';)"
  10.     Else
  11.         ...
  12.     End If
  13.  
  14.     With Forms!frmActionResponse.fsubActions.Form
  15.         .Filter = strFilter
  16.         .FilterOn = True
  17.     End With
  18.  
  19.     Exit Sub
  20. EH:
  21.     MsgBox "There was an error searching for the text!  " & _
  22.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  23.     Exit Sub
  24. End Sub
First, I thinkif you filter by the Responses, you will get some whacked, and perhaps undesired results from the Actions subform. So, instead we filter the Actions subform and the Responses are automatically filtered because of the structural relationship.

If you look closely at the Filter String I've written we are filtering only the ActionIDs that are found in the Responses Table for which the responses contain the search item.

Choosing the other option, you can build a similar Filter String

I hope this hepps!
Mar 15 '18 #6
BHo15
143 128KB
EXCELLENT! I've never done a form filter with a SQL statement. But seeing that is possible, that opens a world of opportunities.

What you said about filtering the Action form instead of the Responses form makes all the sense. I agree... If the Action form is filtered, the Responses form would follow suit.

Thanks so much for the help!
Mar 15 '18 #7
twinnyfo
3,653 Expert Mod 2GB
Glad I could be of service!

[Takes a bow]
Mar 15 '18 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ellen Manning | last post by:
Using A2K. I need the syntax to set the recordsource for a subform within a subform. The "main" subform's recordsource changes based on user input. I need to change the recordsource on the...
0
by: Colin | last post by:
In access 2000 I need to filter records in a Subform by pushing a button on a command button located on the Main form. The Main form is blank. Its only purpose is to contain the subform which is...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
1
by: dmkeith2 | last post by:
OK, This is what I want to do. I have a main table and several other tables with referential integrity based on the tax ID number. My main form is based on the Main Table, I have a subform...
1
by: hakunamatata5254 | last post by:
Hi all, In my project of multiple forms (main form, subform1, 2 , 3 etc) (Main form is Employees, Subforms are Attendance, salary details, payment) Now i want to calculate the payment based...
2
by: mnms | last post by:
Hi, I'm trying to create an "overview" form. And I haven't been able to figure out how to get Access to do what I want yet. Basicly what I want, is to populate a subform based on a field...
0
by: FrozenDude | last post by:
Hello and thanks in advance. I've read through the threads but can't seem to make this work. I have a form with a combo box (named DateCode) that provides a table column name and a subform...
13
by: shreyansghia | last post by:
Hello , I am using MS Access 2007. Now if i ve a subform based on a table, filtering the subform is extremely easy . I only ve to click the relevant column head on the subform and check/uncheck...
28
by: CatrionnaRain | last post by:
Hi All - I'm using 2002 and consider myself an intermediate Access user but newbie programmer :) I've been tasked with the db project from hell and have been combing through posts for the last...
2
by: patriciashoe | last post by:
Greeting All I have several public variables which I use to build a filter string that I would like to use when I open a form and several associated sub forms. I have set the value of the combo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.