Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter Search with Checkbox 1

Status
Not open for further replies.

TieDrPepper

Programmer
Jun 6, 2011
2
US
I am building a string based on a form where user can use several criterias to search, e.g grant number, last name, material weakness, etc. I built the criteria for the combo boxes and text fields, but when I try to build the string with check box I continute to get an error.


If Not IsNull(Me.txtFilterAudNum) Then
strWhere = strWhere & "([Audit_CIN] = """ & Me.txtFilterAudNum & """) AND "
End If

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

If Not IsNull(Me.chkFilterMW) Then
strWhere = strWhere & "([Material_Weakness] = """ & Me.chkFilterMW & """) AND "
End If


'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True (This is where the debugging says the problem is)
End If
 
What about replacing this:
strWhere = strWhere & "([Material_Weakness] = """ & Me.chkFilterMW & """) AND "
with this ?
strWhere = strWhere & "([Material_Weakness] = " & Me.chkFilterMW & ") AND "

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top