Microsoft Access
--
Questions
--
Followers
Top Experts
Compound Filter a Subform - 2 Text Box & 2 Combo
https://www.experts-exchange.com/questions/27590713/Compound-Filter-a-Subform-2-Text-Box-1-Combo.html
I received the perfect answer to my question by pteranodon72
I am now coming back to make an update to this form, I want to add a combo box to the existing filter, but I cannot get the code to work.
The code below works only on the original two text boxes and combo box. I have introduced a new combo box, and edited the code to what I *think* should work, but when I choose a value in the newly added second combo box, I get an 'Enter Paramater Value' box appear.
How can I introduce the second combo box to the filter so it just further compounds my filter?
This is the code I need to edit:
Sub CompoundFilter()
' ================================================
' CODE USED FOR FILTERING ON SPECIFICATIONS SCREEN
' ================================================
Dim strFilter As String 'used to build the criteria of the filter
Dim strCompare As String
Dim cFocus As Control
' =========================
' CODE USED FOR COMBO BOXES
' =========================
'Add Company to Filter, if specified
If IsNull(Me.cboCompanyPicker) = False Then
strFilter = strFilter & " AND CompanyNo=" & Me.cboCompanyPicker.Value
End If
'Add Board Type to Filter, if specified.
If IsNull(Me.cboBoardType) = False Then
strFilter = strFilter & " AND BoardType=" & Me.cboBoardType.Value
End If
' ========================
' CODE USED FOR TEXT BOXES
' ========================
'You must use .text if the control is active, otherwise use .value
If Screen.ActiveControl.Name = "txtFilterSpec" Then
strCompare = Me.txtFilterSpec.Text
Else
strCompare = Nz(Me.txtFilterSpec.Value, "")
End If
' Filter By Spec Number, if specified
If Len(strCompare) > 0 Then
strFilter = strFilter & " AND [SpecificationNo] LIKE '*" & strCompare & "*'"
End If
'You must use .text if the control is active, otherwise use .value
If Screen.ActiveControl.Name = "txtFilterPart" Then
strCompare = Me.txtFilterPart.Text
Else
strCompare = Nz(Me.txtFilterPart.Value, "")
End If
' Filter By Part Number, if specified
If Len(strCompare) > 0 Then
strFilter = strFilter & " AND [PartNo] LIKE '*" & strCompare & "*'"
End If
'Filter or Don't Filter decided here
If Len(strFilter) = 0 Then
'strFilter is still empty -- turn filter OFF
Me.frmSpecificationSubform.Form.FilterOn = False
Else
' one or more conditions is true, so we must trim the extra " AND " off the front
Me.frmSpecificationSubform.Form.Filter = Mid(strFilter, 6)
Me.frmSpecificationSubform.Form.FilterOn = True
End If
End Sub
And the image attached shows my new combo box (yellow).
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
That EnterParameter box appears when a field in your criteria is unrecognized as part of your query.
You should look at the recordsource query for the form that you are filtering and ensure that BoardType (your newly added field in the filter) is indeed part of that query's SELECT clause. Â If not, you need to adjust the query or correct the field name "BoardType" as needed.
In other words, check typing, Â missing spaces such as [Board Type], actual presence of this field in the recordsource of your subform, etc... any of these will cause the parameter prompt to appear.
You should look at the recordsource query for the form that you are filtering and ensure that BoardType (your newly added field in the filter) is indeed part of that query's SELECT clause. Â If not, you need to adjust the query or correct the field name "BoardType" as needed.
In other words, check typing, Â missing spaces such as [Board Type], actual presence of this field in the recordsource of your subform, etc... any of these will cause the parameter prompt to appear.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Thank you very much indeed.... it was the
Which i was missing.
strFilter = strFilter & " AND BoardType=" & chr(34) & Me.cboBoardType.Value & chr(34)
Which i was missing.
Glad that helped :-)
Improperly delimited fields can result in a couple of issues -
- If you mistakenly use quotes or other delimiters on a numeric field, you'll get a type mismatch error.
- If you omit the quotes on a text field (as was the case here), the literal text that you are trying to use for criteria will be mis-interpreted as a field name rather than literal text.
Improperly delimited fields can result in a couple of issues -
- If you mistakenly use quotes or other delimiters on a numeric field, you'll get a type mismatch error.
- If you omit the quotes on a text field (as was the case here), the literal text that you are trying to use for criteria will be mis-interpreted as a field name rather than literal text.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.