More on Filtering forms

  • Thread starter Thread starter Maz Ten
  • Start date Start date
M

Maz Ten

When I put the following code in a form attached to a command button I get a
message saying I can't assign a value to this property then when I debug it
high lights what I have indicated.
Can anyone tell me what to do to overcome this. I am desperate to filter my
form

Dim strFilter As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterState) Then
strFilter = strFilter & "([State] = """ & Me.txtFilterState & """)AND"
End If

lngLen = Len(strFilter) - 5 'Without trailing "AND"
If lngLen < 1 Then
MsgBox "No Criteria"
Else
Me.Filter = Left(strFilter, lngLen) THIS IS HIGH LIGHTED AS can't assign a
value
Me.FilterOn = True
End If

Thanks in advance
Maz T
 
Are you certain that the filter you're passing is a valid
SQL string? Your code trims the last 5 characters from
strFilter which, according to how you've typed it, would
invalidate the SQL string.

You typed:
strFilter = strFilter & "([State] = """ &
Me.txtFilterState & """)AND"

Try this:
strFilter = strFilter & "([State]='" _
& Me!txtFilterState & "') AND "

Good luck.
 
Back
Top