Ok, here is the entire code.
Option Compare Database
Option Explicit
Private Sub cmdSearchDate_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([Start Date] = " & Format(Me.txtStartDate,
conJetDate) & ") AND "
End If
If Not IsNull(Me.txtEndDate) Then
strWhere = strWhere & "([End Date] = " & Format(Me.txtEndDate,
conJetDate) & ") AND "
End If
If Not IsNull(Me.txtInvoiceNumber) Then
strWhere = strWhere & "([Invoice Number] = " & Me.txtInvoiceNumber
&
") AND "
End If
If Me.txtInvoiceStatus = -1 Then
strWhere = strWhere & "([Invoice Status] = True) AND "
ElseIf Me.txtInvoiceStatus = 0 Then
strWhere = strWhere & "([Invoice Status] = False) AND"
End If
If Me.txtRSAType = -1 Then
strWhere = strWhere & "([RSA Type] = True) AND "
ElseIf Me.txtRSAType = 0 Then
strWhere = strWhere & "([RSA Type] = False) AND"
End If
If Me.txtStaffingType = -1 Then
strWhere = strWhere & "([Staffing Type] = True) AND "
ElseIf Me.txtStaffingType = 0 Then
strWhere = strWhere & "([Staffing Type] = False)AND"
End If
If Not IsNull(Me.txtEmployeeOut) Then
strWhere = strWhere & "([Employee Out] = """ & Me.txtEmployeeOut &
""") AND "
End If
If Me.txtSiteName = -1 Then
strWhere = strWhere & "([Site Name] = True) AND "
ElseIf Me.txtSiteName = 0 Then
strWhere = strWhere & "([Site Name] = False)"
End If
lngLen = Len(strWhere) - 1
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "Please select a criteria", vbInformation, "No Criteria!"
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
here is each criteria field I use each time and their respective error in
the
imidiate window.
Start Date + End Date
([Start Date] = #01/22/2007#) AND ([End Date] = #01/22/2007#)AND
Invoice Number
([Invoice Number] = 1078665)AND
Employee Out
([Employee Out] = "Jaron Mclurin") AND
But when I use the combo box fields the code does not look into those
fields
and if the other fields are blank then it will disply the "No Criteria"
message.
As you can see all my field names that have a space are closed in
brackets.
And I have looked several times to make sure that the field names and the
crieteria field names are consistent with those in the code. Thanks again
for
your responses. Please look if you can see something I haven't been able
to.
Allen said:
Okay, the error message indicates that the string is not correctly formed,
and so cannot be assigned to the form's filter.
Just above that line, enter:
Debug.Print strWhere
When it fails, open the Immediate Window (Ctrl+G), and see what printed
there. You need to correct your code so it generates a value WHERE clause.
If you have spaces in your field names, enclose them in square brackets,
e.g.:
[Start Date]
the error occurs at this line.
[quoted text clipped - 16 lines]
the filter and one to clear the filter. I only need help for the
first
one.