Link to home
Create AccountLog in
Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Avatar of Computer_Support_Norwich
Computer_Support_Norwich🇬🇧

Compound Filter a Subform - 2 Text Box & 2 Combo
User generated imageA few months ago I posted this question about compound filtering a form with text boxes and a combo box, with the filtered data updating after every keystroke into a text box:

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

Open in new window


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.


Avatar of mbizupmbizup🇰🇿

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.

ASKER CERTIFIED SOLUTION
Avatar of mbizupmbizup🇰🇿

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Computer_Support_NorwichComputer_Support_Norwich🇬🇧

ASKER

Thank you very much indeed.... it was the

strFilter = strFilter & " AND BoardType=" & chr(34) & Me.cboBoardType.Value & chr(34) 

Open in new window


Which i was missing.

Avatar of mbizupmbizup🇰🇿

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.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Access

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.