Allen said:
You cannot have the query read an entire expression including the
operators like that.
Instead, build the filter dynamically. You can then use it in the Filter
of a form, the WhereCondition of OpenReport, or the entire SQL statement
(e.g. for the RecordSource of a form, or the RowSource of a combo, or the
SQL property of a QueryDef.)
Here's a simple example:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html
Here's a more comprehensive one:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
Thanks Allen I looked at the second link and decided on an unbound form
with unbound textboxes, I will use these textboxes to set my criteria for
an unbound listbox on another form...here is what I have but it isn't
quite returning anything but an empty listbox. Any suggestions welcomed!
Thanks
DS
With Forms!frmFXReproduce!ListStats
.RowSource = "SELECT Format([ChkDate],""m/dd/yyyy"") AS DT,
tblChecks.ChkTime, tblChecks.CheckID, " & _
"tblChecks.ChkAlias, [EmpFirstName] & "" "" & [EmpLastName] AS SRV, "
& _
"tblChecks.ChkPaid, tblChecks.ChkCancelled, tblChecks.ChkTabID,
tblChecks.ChkAlias & "" / "" & tblChecks.ChkGuests AS INFO, " & _
"tblChecks.ChkServer, tblChecks.ChkKillTax, tblChecks.ChkDividedCheck,
tblChecks.ChkTotal, tblChecks.ChkBizDay " & _
"FROM tblChecks INNER JOIN tblEmployees ON tblChecks.ChkServer =
tblEmployees.EmployeeID " & _
"WHERE (((tblChecks.ChkTime) >=
[Forms]![frmFXReproduceSearch]![TxtTimeStart]Is Null) " & _
"OR (tblChecks.ChkTime) >=
[Forms]!frmFXReproduceSearch]![TxtTimeStart]) " & _
"And (tblChecks.ChkTime) <=
[Forms]![frmFXReproduceSearch]![TxtTimeEnd]Is Null) " & _
"OR (tblChecks.ChkTime) <=
[Forms]![frmFXReproduceSearch]![TxtTimeEnd]) " & _
"And ((tblChecks.CheckID) >=
[Forms]![frmFXReproduceSearch]![TxtCheckStart]Is Null) " & _
"OR ((tblChecks.CheckID) >=
[Forms]![frmFXReproduceSearch]![TxtCheckStart] " & _
"And (tblChecks.CheckID) <=
[Forms]![frmFXReproduceSearch]![TxtCheckEnd]IS Null) " & _
"OR (tblChecks.CheckID) <=
[Forms]![frmFXReproduceSearch]![TxtCheckEnd]) " & _
"And ((tblChecks.ChkPaid) = -1) And ((tblChecks.ChkCancelled) = 0) And
((tblChecks.ChkTabID) = [Forms]![frmFXReproduceSearch]![TxtTabID]) " & _
"And ((tblChecks.ChkServer) =
[Forms]![frmFXReproduceSearch]![TxtServer]Is Null) " & _
"OR ((tblChecks.ChkServer) =
[Forms]![frmFXReproduceSearch]![TxtServer]) " & _
"And ((tblChecks.ChkTotal) >=
[Forms]![frmFXReproduceSearch]![TxtAmountStart]Is Null) " & _
"OR ((tblChecks.ChkTotal) >=
[Forms]![frmFXReproduceSearch]![TxtAmountStart] " & _
"And (tblChecks.ChkTotal) <=
[Forms]![frmFXReproduceSearch]![TxtAmountEnd]Is Null) " & _
"OR (tblChecks.ChkTotal) <=
[Forms]![frmFXReproduceSearch]![TxtAmountEnd]) " & _
"And ((tblChecks.ChkDate) >=
[Forms]![frmFXReproduceSearch]![TxtDateStart]Is Null) " & _
"OR ((tblChecks.ChkDate) >=
[Forms]![frmFXReproduceSearch]![TxtDateStart] " & _
"And (tblChecks.ChkDate) <=
[Forms]![frmFXReproduceSearch]![TxtDateEnd]Is Null)) " & _
"OR (tblChecks.ChkDate) <=
[Forms]![frmFXReproduceSearch]![TxtDateEnd])) " & _
"ORDER BY tblChecks.ChkTime DESC;"
.ColumnCount = 14
.ColumnWidths = "0.8 in;0.75 in;1 in;1.2 in;1.4 in;0 in;0 in;0 in;0
in;0 in;0 in;0 in;0.8 in;0 in"
.Requery
End With