TieDrPepper
Programmer
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
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