473,666 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subform filtering

33 New Member
I'm getting no error messages here, but I'm not getting any results visible when the filter is applied. There are 2 unbound combo boxes in the main form, SetStudy and SetCDB. The only possible values for the column [ROLE] are the 9 reflected in the code below. (The form and table for [ROLE] have the Row Source: "CEC Chair";"CEC Co-Chair";"CEC Member";"DSMB Chair";"DSMB Co-Chair";"DSMB Member";"CEC/DSMB Chair";"CEC/DSMB Co-Chair";"CEC/DSMB Member")

Expand|Select|Wrap|Line Numbers
  1. Private Sub SetCDB_AfterUpdate()
  2. If Me.SetCDB.Selected(0) Then
  3.     Me.SubR.Form.Filter = "[ROLE] = " & Chr(34) & "CEC Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  4. ElseIf Me.SetCDB.Selected(1) Then
  5.     Me.SubR.Form.Filter = "[ROLE] = " & Chr(34) & "DSMB Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "DSMB Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "DSMB Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  6. ElseIf Me.SetCDB.Selected(2) Then
  7.     Me.SubR.Form.Filter = "[ROLE] = " & Chr(34) & "CEC/DSMB Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC/DSMB Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC/DSMB Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  8. Else
  9.     Me.SubR.Form.Filter = "[ROLE ID] = 0"
  10. End If
  11. Me.SubR.Form.FilterOn = True
  12. SubR.Requery
  13. End Sub
Any ideas what's going wrong with the filtering?
Dec 29 '15 #1
12 1149
zmbd
5,501 Recognized Expert Moderator Expert
line 12: Me!SubR.Form.Re fresh

you shouldn't need a new query if all you are doing is applying a filter to the form's current record-set; however,

line 12: Me!SubR.Form.Re query
Dec 29 '15 #2
abcrf
33 New Member
Thanks, Z, but that wasn't it. It's performing the same with both syntaxes.
Dec 29 '15 #3
zmbd
5,501 Recognized Expert Moderator Expert
The most common issue is a malformed string which is why I always build my strings first and then set to the form or the called function.

Give me a moment to double check things....
Dec 29 '15 #4
zmbd
5,501 Recognized Expert Moderator Expert
Ok, a little re-arrangement on the code

Expand|Select|Wrap|Line Numbers
  1. Private Sub SetCDB_AfterUpdate()
  2.     Dim zSQL As String
  3.     Dim zSelected as Integer
  4. '
  5.     zSelected = Me.setcdb.value
  6. '
  7.     Select Case zSelected
  8.         Case 1
  9.             zSQL = "[ROLE] = " & Chr(34) & "CEC Chair" & Chr(34) & _
  10.                 " Or [ROLE] = " & Chr(34) & "CEC Co-Chair" & Chr(34) & _
  11.                 " Or [ROLE] = " & Chr(34) & "CEC Member" & Chr(34) & _
  12.                 " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  13.         Case 2
  14.             zSQL = "[ROLE] = " & Chr(34) & "DSMB Chair" & Chr(34) & _
  15.                 " Or [ROLE] = " & Chr(34) & "DSMB Co-Chair" & Chr(34) & _
  16.                 " Or [ROLE] = " & Chr(34) & "DSMB Member" & Chr(34) & _
  17.                 " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  18.         Case 3
  19.             zSQL = "[ROLE] = " & Chr(34) & "CEC/DSMB Chair" & Chr(34) & _
  20.                 " Or [ROLE] = " & Chr(34) & "CEC/DSMB Co-Chair" & Chr(34) & _
  21.                 " Or [ROLE] = " & Chr(34) & "CEC/DSMB Member" & _
  22.                 Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  23.          Case Else
  24.             zSQL = "[ROLE ID] = 0"
  25.     End Select
  26. '
  27. Debug.Print zSQL
  28. '
  29.     Me!SubR.Form.Filter = zSQL
  30. '
  31.     Me!SubR.Form.FilterOn = True
  32. '
  33.     Me!SubR.Form.Refresh
  34. '    Me!SubR.Requery
  35. End Sub
Open the VBE, <CTRL><G> to open the immediate panel

Run your form

Check the immediate panel for properly formatted string for the filter

((another option along the line of the OP code))

Expand|Select|Wrap|Line Numbers
  1. Private Sub SetCDB_AfterUpdate()
  2.     Dim zSQL As String
  3. '
  4.     Select Case  Me.setcdb.ListIndex
  5.         Case 0
  6.             zSQL = "[ROLE] = " & Chr(34) & "CEC Chair" & Chr(34) & _
  7.                 " Or [ROLE] = " & Chr(34) & "CEC Co-Chair" & Chr(34) & _
  8.                 " Or [ROLE] = " & Chr(34) & "CEC Member" & Chr(34) & _
  9.                 " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  10.         Case 1
  11.             zSQL = "[ROLE] = " & Chr(34) & "DSMB Chair" & Chr(34) & _
  12.                 " Or [ROLE] = " & Chr(34) & "DSMB Co-Chair" & Chr(34) & _
  13.                 " Or [ROLE] = " & Chr(34) & "DSMB Member" & Chr(34) & _
  14.                 " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  15.         Case 2
  16.             zSQL = "[ROLE] = " & Chr(34) & "CEC/DSMB Chair" & Chr(34) & _
  17.                 " Or [ROLE] = " & Chr(34) & "CEC/DSMB Co-Chair" & Chr(34) & _
  18.                 " Or [ROLE] = " & Chr(34) & "CEC/DSMB Member" & _
  19.                 Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  20.          Case Else
  21.             zSQL = "[ROLE ID] = 0"
  22.     End Select
  23. '
  24. Debug.Print zSQL
  25. '
  26.     Me!SubR.Form.Filter = zSQL
  27. '
  28.     Me!SubR.Form.FilterOn = True
  29. '
  30.     Me!SubR.Form.Refresh
  31. '    Me!SubR.Requery
  32. End Sub
Dec 29 '15 #5
abcrf
33 New Member
I'm getting an "argument not optional" error for .Selected using the "Case" structure above, but I'll try using that string technique with my original code.
Dec 29 '15 #6
abcrf
33 New Member
Interesting result, though it fits with the initial problem.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SetCDB_AfterUpdate()
  2. Dim zSQL As String
  3. Forms!FRM_ROLES!SubR!SubStudy.DefaultValue = Chr(34) & Me.SetStudy.Value & Chr(34)
  4. If Me.SetCDB.Selected(0) Then
  5.     zSQL = "[ROLE] = " & Chr(34) & "CEC Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  6. ElseIf Me.SetCDB.Selected(1) Then
  7.     zSQL = "[ROLE] = " & Chr(34) & "DSMB Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "DSMB Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "DSMB Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  8. ElseIf Me.SetCDB.Selected(2) Then
  9.     zSQL = "[ROLE] = " & Chr(34) & "CEC/DSMB Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC/DSMB Co-Chair" & Chr(34) & " Or [ROLE] = " & Chr(34) & "CEC/DSMB Member" & Chr(34) & " And [STUDY NAME] = " & Chr(34) & Me.SetStudy.Value & Chr(34)
  10. Else
  11.     zSQL = "[ROLE ID] = 0"
  12. End If
  13. Debug.Print zSQL
  14. Me!SubR.Form.Filter = zSQL
  15. Me!SubR.Form.FilterOn = True
  16. Me!SubR.Form.Refresh
  17. End Sub
Gives the response:
Expand|Select|Wrap|Line Numbers
  1. [ROLE ID] = 0
Dec 29 '15 #7
zmbd
5,501 Recognized Expert Moderator Expert
I was afraid of that... I've not used the selected property like that before... I'll revise the post

The selected property is usually used to set a selection in a list box.

I've re-written the code to use the value of the cbox instead; however, this is assuming that the cbox has the bound column set so that the first selection returns 1, the second 2, etc...
Dec 29 '15 #8
abcrf
33 New Member
Turns out I was using the wrong syntax for .Selected; it needs to be in the format Me.SetCDB.Selec ted(0) = True.

But with it corrected in the code above, I get the same string printed, so maybe that's not the location of the error?
Dec 29 '15 #9
zmbd
5,501 Recognized Expert Moderator Expert
The selected property isn't used to retrieve the row selected, it is used to set the selected row.
(This will not however, set the value of the cbox)

Please see the revised code in Post#5

Two options
First Option
The revision now will return the value of the bound column for the cbox in Line 5 and the compare against the select...case starting on line 7.

Of course, you may have to modify the Case comparisons based upon what the actual return is for the cbox's bound column.

Second Option:
Just thought of this: We could potentially us the listindex property... and this more closely matches your original logic. Not really how I would approach the use of a combobox...

you got me "out of the box" on this one ;-)
Dec 29 '15 #10

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

Similar topics

3
11097
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I have a primary form named TestResults, which is connected to data in a table named TestResults. There are basically two other tables that are related to the TestResults table (and the primary form) named Names-Normalized and SiteAddresses. The...
19
3534
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the user clicks on the first list box (lstCollege), it returns values in the second list box...
0
1930
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set to and the source object is the subform. My subform record source is a query from another table (vacationTbl). FYI: I was filtering on the subform, but removed it and replaced with
1
4933
by: aintnorock | last post by:
I have a relatively simple relational database. One of my forms is based on a query with a 3 parameter sort: Status / Priority / Customer. When I open the form, the records are sorted properly. When I go to filter the form, to get a subset of the form, e.g. filter by Responsible Party, I would like the form to sort this way: Reposponsible Party / Status / Priority / Customer.
1
1607
by: crazytegger | last post by:
I am trying to filter a subforms combolist options through a combolist on the main form. Heres what i have: Form: frmOrderDetail Datasource: tblOrders cmbOrderSupplierID w/ control source orders. Subform: frmOrderDetailSubform datasource: qryOrderDetails cmbItemID w/ row source: SELECT ., .
3
1576
by: BSTAFFORD | last post by:
I was researching some vba code on TheScripts.com and found this post. I’m looking to accomplish the same idea but I need to filter a sub form query with 3 combo boxes from the main form. This is part of a tech support call log that I’m implementing as a sort of post production quality control log. I appreciate any help you can give me
0
1685
by: diogenes | last post by:
"Rick Brandt" <rickbrandt2@hotmail.comwrote in news:bPnKj.456$%41.325 @nlpi064.nbdc.sbc.com: I used this approach, and it works a treat! ID In(SELECT Order_ID FROM orderitems WHERE NAME = 'product') I've not used an In clause before. Thanks a lot for the education.
5
7106
by: jbrumbau | last post by:
Hello, I have some specification sheets with subforms I have created. I'm having a problem where if you right click and filter/sort any field in the subform (which is tied to the main form in a 1:1 relationship), then the subform only displays the first record. This ends up permanently altering the spec sheet. I notice that when this happens, text typically shows up in the "Order By" or "Filter" fields of the subform. My only resort is to...
6
1482
by: lovelydan | last post by:
I have designed a form(main form) which has a record source that runs subforms. this works perfectly. I also have a macro that is attached to this subform which filters records on a different form. One of my subforms contains personnel IDs and few details. When I click on the ID field the macro runs and opens another form, filtering it by the ID number. This works when the subform is opened independently but when the subform is opened on a...
4
4600
zmbd
by: zmbd | last post by:
Ok, So I've created forms with both filtering as in http://bytes.com/topic/access/insights/590551-example-filtering-form, same concept with cascading comboboxs, and I have used Main/Subform formats too for related tables/queries. I think it is my inexperience in that I do not see the inherent advantages of the subform vs. the filtered form and have used both methods depending on what forms I'd already constructed (and their underlying vba)....
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5661
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.