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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nightmare- Query!

Status
Not open for further replies.

ianbar

Technical User
Jan 10, 2003
69
GB
Hi I have a form that has several search criteria text fields on it, when some fields are blank the query fails to work even though I have used IIF statements in the query for fields that could possibly be blank.

Here is a copy of the query from sql view:

SELECT TRACKER.RecordID, TRACKER.SOCCSType, TRACKER.DateRaised, TRACKER.RaisedBy, TRACKER.Company, TRACKER.DueDate, TRACKER.Status, TRACKER.ClosedDate, TRACKER.Link
FROM TRACKER
WHERE (((TRACKER.SOCCSType)=IIf([Forms]![Search].[txtsoccstype]<>&quot;&quot;,[Forms]![Search].[txtsoccstype],&quot;*&quot;)) AND ((TRACKER.Company) Like &quot;*&quot; & [Forms]![Search].[txtsearchcriteria] & &quot;*&quot;) AND ((TRACKER.Status)=IIf([Forms]![Search].[txtsoccstype]<>&quot;&quot;,[Forms]![Search].[txtstatus],&quot;*&quot;)));


Can anyone help me?
 
Try breaking it down, check out my code post Mar 6 at this thread

thread702-490663

Split up the sql string and rebuild it after checking each search criteria, finally adding the last bit of the string.

The counter (n) is just a check as to whether criteria exist, if no criteria then it sets sql without a where condition.

Telephoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top