Trying to filter by 3 dropdowns on my form. continually getting error 3075

the-m0th

Registered User.
Local time
Today, 01:13
Joined
Apr 14, 2015
Messages
51
Hi Everyone,

I'm currently trying to put 3 dropdowns on a form that will allow me to filter the table behind it but i keep getting error 3075.

This is the code i'm using.

Code:
Private Sub cmd_filter_Click()
    Dim strFilter As String
    Dim strConj As String
    
    strConj = " AND "  ' could be " OR "
    
    With Me.cbo_wardfilter
        If Not IsNull(.Value) Then
        strFilter = strFilter & strConj & _
            "(Ward = '" & .Value & "')"
            End If
    End With
        
    With Me.cbo_agefilter
        If Not IsNull(.Value) Then
            strFilter = strFilter & strConj & _
                "(Age Range = '" & .Value & "')"
        End If
    End With
        
    With Me.cbo_sex
        If Not IsNull(.Value) Then
            strFilter = strFilter & strConj & _
                "(Gender = '" & .Value & "')"
        End If
    End With
    
    If Len(strFilter) > 0 Then
        ' Trim off leading conjunction, if any, then apply the filter.
        strFilter = Mid$(strFilter, Len(strConj) + 1)
        Me.Filter = strFilter
        Me.FilterOn = True
    Else
        ' Remove any filter that may be active.
        Me.FilterOn = False
        Me.Filter = vbNullString
    End If
End Sub

it keeps hanging on the 8th linbe up - Me.Filter = strFilter

any help you guys can give will be thankfully received.

Wayne
 
did you stop the code here? F9
what is the value of strFilter?

the code looks fine, but what are the values>
 
Hi,

I've got it to print the value of strFilter to a text file and it's currently

(Ward = 'Birchanger') AND (Age Range = '50 - 74') AND (Gender = 'Female')

it's totally got me beat.
 
The field with the inadvisable space needs to be bracketed.
 
square brackets? cheers for the help guys, it's always those bloody square brackets.
 
Yes, the square brackets, but you only need them because of the bloody spaces! :p
 

Users who are viewing this thread

Back
Top Bottom