473,416 Members | 1,818 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,416 software developers and data experts.

Filtering a subform based on interactive dropdowns

8 Byte
I would appreciate assistance in pointing me in the right direction. I've found some post that are very somewhat close to my challenge but not quite.

I have 3 interactive dropdowns (I'd prefer to keep them as interactive dropdowns and not cascading dropdowns). I do not need help with the interactive dropdowns, but they do show up as unbound in design view. The dropdowns are limited to values in table1. Depending on the selection of the interactive drop downs, I would like my subform to display results based on the selection of the dropdowns. I tried the parent/child approach but that didn't work since the dropdowns are showing up as unbound. I've come to the conclusion I need to do more filtering at the AfterUpdate event for all of the dropdowns, but not sure how to apply that to a subform.

I've included an image because I feel like reading descriptions of tables can be difficult to conceptualize sometimes. Thank you!

Attached Images
File Type: jpg Access_SubformFilteringIssue.jpg (114.5 KB, 564 views)
Jan 10 '21 #1

✓ answered by NeoPa

The concept should be relatively straightforward if you consider it step-by-step.

First of all you want a process to run whenever any of your ComboBoxes are updated. You may also want the same process to run when you open the form originally. Thus we would consider a Procedure which is called from all those places.

The process would build a filter string based on all of the ComboBoxes, being flexible enough to ensure any empty ComboBox is excluded from the filter.

At the end of the Procedure the filter string needs to be applied and the Form (Of whatever type - SubForm; Pop-Up; Current Form; whatever.) Requeried.

To illustrate I've knocked up some boilerplate code. The names will likely differ from yours and the precise circumstances may need to be adjusted but it should give you the basic concept :
Expand|Select|Wrap|Line Numbers
  1. Private Sub DoFilter(frmVar As Form)
  2.     Dim strWhere As String
  3.  
  4.     With Me
  5.         If Not IsNull(.cboNum) Then
  6.             strWhere = strWhere & " AND ([NumField]=%N)"
  7.             strWhere = Replace(strWhere, "%N", .cboNum)
  8.         End If
  9.         If Not IsNull(.cboDate) Then
  10.             strWhere = strWhere & " AND ([DateField]=#%D#)"
  11.             strWhere = Replace(strWhere, "%D", Format(.cboDate, "yyyy\-m\-d"))
  12.         End If
  13.         If Not IsNull(.cboString) Then
  14.             strWhere = strWhere & " AND ([StringField]='%S')"
  15.             strWhere = Replace(strWhere, "%S", .cboString)
  16.         End If
  17.         If strWhere > "" Then strWhere = Mid(strWhere, 6)
  18.     End With
  19.     With frmVar
  20.         If .Filter <> strWhere Then
  21.             .Filter = strWhere
  22.             .FilterOn = (strWhere > "")
  23.         End If
  24.     End With
  25. End Sub

16 3515
NeoPa
32,556 Expert Mod 16PB
I'm having a deal of trouble trying to understand where you're coming from.

Can you explain why it wouldn't be as simple as filtering the subform based on the selected values in your ComboBoxes? The _AfterUpdate() code would build up the filter string based on any & all values present but ignore items with no value set. Is that not what you're after? If not then I'm thoroughly confused.
Jan 10 '21 #2
kara507
8 Byte
I think you understand correctly!

My challenge is that I haven't been able to find examples that would hint at how to approach it with multiple criteria (the dropdowns) and how to apply the criteria to table2. Most of the examples I've seen online are just a little bit too different for me to feel confident that it is the right approach. Setting up the interactive dropdowns was ok once I found parallel code, but the two reference textbooks I'm using (Access Bible and Microsoft Access 2019 Programming by Example) isn't quite sufficient to apply the filtering to the subforms.

For the filtering, I'm assuming I'd build a string that would retrieve the corresponding source ID based on dropdown criteria, and then have the subform spit out the available test results from table2 based on the source ID identified? I think I'm just stumped on how to bring the subform into the filtering since many examples use the parent/child approach.

Thank you!
Jan 10 '21 #3
isladogs
456 Expert Mod 256MB
I'm still unclear what an interactive dropdown is other than a standard combo box. Am I missing something?

I think you just want examples showing how to apply multiple filters to your form/subform. If I'm correct then I have several examples on my website that may be helpful to you. Try a Google search for 'Multiple Group & Filter - Mendip Data Systems'
Jan 10 '21 #4
kara507
8 Byte
Sorry for the confusion. I may be using the wrong terminology here.

I've set up the drop downs so that if you select a State, the only available for the other dropdowns are ones that have records associated with that state. The dropdowns do not have be used in a specific order. If I understand correctly, cascading forces the user to select in a certain order and that wasn't something I quite wanted in my project. I wanted the user to be able to use the dropdowns in any order and still have the subsequent dropdowns influenced by the selection in other dropdowns. For example, based on the image provided above, there would be no way for a user to select State = PA and Type = Pond because no such entry exist in table1.

The non-cascading (interactive?) dropdowns may be irrelevant here. I only specified it since some examples I've seen use strictly the last dropdown in the cascade series to filter the subform which isn't quite what I wanted.

I'll do some google searching with the terms you suggested. Thank you!
Jan 10 '21 #5
isladogs
456 Expert Mod 256MB
Sorry but that sounds like you are using cascading combos as the second combo values depend on the value selected in the first combo. The webpage I suggested earlier was for separate combos being used to filter different fields in the same dataset.

I also have a cascading combos example with 5 related combos. Forum rules prevent me providing a link but you can find that with a search for 'cascading combo boxes Mendip data systems'
Jan 10 '21 #6
kara507
8 Byte
I certainly won't argue if you say it is cascading combo boxes, you definitely know more than me! :)

In my case, I'm looking for examples to review on how to filter the subform (table2) based on the combo box selection (table1). I thought your first example that you provided might help me out a little bit, but I'm not sure that the dropdowns and the detail results are separate tables? It looks like your dropdowns and resulting tables are both from the PupilData table.

I'll take a look at the second example you recommended. Thank you!
Jan 10 '21 #7
NeoPa
32,556 Expert Mod 16PB
The concept should be relatively straightforward if you consider it step-by-step.

First of all you want a process to run whenever any of your ComboBoxes are updated. You may also want the same process to run when you open the form originally. Thus we would consider a Procedure which is called from all those places.

The process would build a filter string based on all of the ComboBoxes, being flexible enough to ensure any empty ComboBox is excluded from the filter.

At the end of the Procedure the filter string needs to be applied and the Form (Of whatever type - SubForm; Pop-Up; Current Form; whatever.) Requeried.

To illustrate I've knocked up some boilerplate code. The names will likely differ from yours and the precise circumstances may need to be adjusted but it should give you the basic concept :
Expand|Select|Wrap|Line Numbers
  1. Private Sub DoFilter(frmVar As Form)
  2.     Dim strWhere As String
  3.  
  4.     With Me
  5.         If Not IsNull(.cboNum) Then
  6.             strWhere = strWhere & " AND ([NumField]=%N)"
  7.             strWhere = Replace(strWhere, "%N", .cboNum)
  8.         End If
  9.         If Not IsNull(.cboDate) Then
  10.             strWhere = strWhere & " AND ([DateField]=#%D#)"
  11.             strWhere = Replace(strWhere, "%D", Format(.cboDate, "yyyy\-m\-d"))
  12.         End If
  13.         If Not IsNull(.cboString) Then
  14.             strWhere = strWhere & " AND ([StringField]='%S')"
  15.             strWhere = Replace(strWhere, "%S", .cboString)
  16.         End If
  17.         If strWhere > "" Then strWhere = Mid(strWhere, 6)
  18.     End With
  19.     With frmVar
  20.         If .Filter <> strWhere Then
  21.             .Filter = strWhere
  22.             .FilterOn = (strWhere > "")
  23.         End If
  24.     End With
  25. End Sub
Jan 11 '21 #8
kara507
8 Byte
Hi NeoPa!

I totally follow your suggestion of building a procedure that runs at the afterupdate event of the combo boxes. This procedure would create the string of the “where” SQL conditions. Do you have any tips on how to apply this to the subform?

Under property sheet, my subform has a source object of table2. I do not see any filtering options on the property sheet except “Filter on Empty Master.” I am wondering if I need to create a new table2 and somehow integrate the resulting filter string into the and reference that dynamic table as the source object instead of table2?

Thank you for writing!


@NeoPa
Jan 11 '21 #9
NeoPa
32,556 Expert Mod 16PB
I'm not sure I understand where your confusion is coming from. The procedure I showed as an example has the Form passed to it and every Form has the .Filter & .FilterOn properties so the example code already does that for you.
Jan 11 '21 #10
kara507
8 Byte
My apologies!!! I totally missed the top where you specify that you were passing a form into the subroutine. I've only worked with subroutines where you pass a maybe a script into it, but never a form. I had no idea you were could pass a form into a subroutine!!! I'll try it out and see if I can get it work! Thank you!

Private Sub DoFilter(frmVar As Form)

@NeoPa
Jan 11 '21 #11
NeoPa
32,556 Expert Mod 16PB
We always have to bear in mind that a forum, by its very nature (Global; internet; etc.), is home to people of all levels of intelligence; experience; nationality; etc. Often it's unclear where the limitations are from but it generally doesn't matter. It's perfectly understandable not to understand everything at first glance if it's something that's new to you. There's a lot to pick up.

In all honesty there are so many possible ways to approach this. The Form needn't be passed as a parameter if it's always the same one and the code has access to it easily already. Passing it as a parameter in this instance was to ensure the name was clearly associated with the Form so any code referencing frmVar in the body was more easily understood. You could take the same approach with the various ComboBoxes too if you preferred.
Jan 11 '21 #12
kara507
8 Byte
I did not want to start a new topic if it wasn't necessary.

I spent more time with the Multiple Group Filter this week. Thank you for making this available for review. I think I'm connecting the dots a little more. May I ask how what design control (ex: subform, textbox, etc) is being used for pupil data? I thought it would simply be a subform, but it looks different than most examples I've seen with a subform.

Thank you!
Jan 16 '21 #13
NeoPa
32,556 Expert Mod 16PB
I'm afraid you've completely thrown me with this one. You seem to be asking me about the design you have in your database, or in your head, I'm not sure. Why would you ask me that? Nothing in what I posted limits your options in that respect as far as I know.

I'd like to be able to help further but I can't see how at this point.
Jan 16 '21 #14
kara507
8 Byte
NeoPa!

First, thank you so much for your assistance earlier! I learned so much!

I apologize for the confusion, I thought I hit reply directly under one of isladogs post. This person encouraged me to google search Mendip Multiple Group & Filter. Google searching these terms took me to an example access file to view. My general (perhaps embarrassing question) was asking if the table under the filter options was a subform? Under design view, it doesn't quite look like a subform set up. I didn't want to start a new post to ask this question.

I don't know who you are, but I'm very grateful that you took the time to respond.

Edit - I think I just figured it out! It took me a while to find it, but it isn't a subform like I expected. The property sheet just says the Selection Type: Form, Continuous Form. I'll have to see if I can figure out how to add that. So much to learn!

Thank you!
Jan 16 '21 #15
NeoPa
32,556 Expert Mod 16PB
Hi Kara.

Your explanation now makes perfect sense & puts everything into perspective that I couldn't see before :-)
Kara507:
I don't know who you are, but I'm very grateful that you took the time to respond.
While it is by no means expected for members to share who they are, I have no problems with it. If you click on my NeoPa Profile link you can see a bit about me. I'm Adrian Bell and I'm a Microsoft MVP for Access.
Jan 16 '21 #16
isladogs
456 Expert Mod 256MB
Hi Kara
There isn't a subform.
My example app that you referred to is just a continuous form with textboxes for each field in the detail section.
However the header section has a series of command buttons instead of labels for each field header. Clicking on any of those buttons allows you to sort by that field. Clicking again reverses the sort...



BTW 2 fields have aliases which include a '?'. There are no special characters in the field names

Happy to answer other general questions as part of this thread. However, if you have more detailed questions regarding my app, it may be better to PM me as others won't be necessarily have the example app available to view
Attached Images
File Type: jpg Screenshot 2021-01-16 091128.jpg (141.4 KB, 448 views)
Jan 16 '21 #17

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

Similar topics

3
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
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...
2
Scott Price
by: Scott Price | last post by:
Hello again! Running MS Access 2003 on WinXPproSP2. Now I'm trying to re-filter my subform based on the currently shown Year field (the filter applied on open restricts to 15 records relating...
8
by: NJonge01 | last post by:
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes...
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...
1
by: daleshei | last post by:
I have a combo box with list all the queries I have on my database: Form is called: frm_qry_slct Combo box (Unbound): Combo23 RowSourceType: Table/Query RowSoource:SELECT FROM MSysObjects...
2
by: csolomon | last post by:
Happy Hump Day! I was wondering if it would be possible to some how resize my subform based on the number of records it holds. I have a subform that I populate via a non-updatable query. It just...
12
by: kashif73 | last post by:
Hi, I have a subform (datasheet view) on my Mainform, where a user can enter information. I need help on how to display the required number of rows in my subform based on the number selected in...
5
by: hbaf208 | last post by:
I have a combobox on a subform that is based on an SQL that uses a listbox on the unbound parent form as the criteria. When the form is first loaded, it works perfectly, limiting the dropdowns to...
1
Jerry Maiapu
by: Jerry Maiapu | last post by:
I have a many to many relationship implemented into a db with 2 parent forms with their respective child forms. ( 3 tables, 1 link table) for each subform I have a lookup combo on FK Field...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.