Try something along the lines of the following.
If IsNull(frm!txtCountyHolder.Value) Then 'County
str1 = ""
Else
str1 = " AND qryX.txtCounty = """ & frm!txtCountyHolder.Value & """"
End If
'-------------------------------------------
If IsNull(frm!txtCategoryHolder.Value) Then 'Category
str2 = ""
Else
str2 = " AND qryX.TxtCat = """ & frm!txtCategoryHolder.Value & """"
End If
1 strSQL = "SELECT qryX.PropertyID, qryX.txtCnty, qryX.txtCat "
2 strSQL = strSQL & "FROM qryX "
3 strSQL = strSQL & "Where TRUE " 'County
4 strSQL = strSQL & str1
5 strSQL = strSQL & str2
Actually I would use something more along the lines of
Dim StrWhere as String
Dim strSQL as String
IF IsNull(frm!txtCountyHolder) = False Then
strWhere = strWhere & " AND qryX.txtCounty = """ &
frm!txtCountyHolder.Value & """"
END IF
IF IsNull(frm!txtCategoryHolder) = False Then
strWhere = strWhere & " AND qryX.txtCat = """ &
frm!txtCategoryHolder.Value & """"
End If
'build the SQL statement
strSQL = "SELECT qryX.PropertyID, qryX.txtCnty, qryX.txtCat "
strSQL = strSQL & "FROM qryX "
'Strip of the leading "and" conjunction
strSQL = strSQL & Mid(StrWhere,5)
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County