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

Query Criteria from text on form

Status
Not open for further replies.

gazza110

Technical User
Apr 14, 2004
42
GB
Hi,

I have created a list box on a form that can have multiple values. I have managed to create a text box that calculates what the Criteria in a query should be. This referes to keywords. If the keywords "apple" "orange" and "pear" were in the list box, the text box would read
Code:
"apple" or "orange" or "pear"
. When trying to refer to the text box for the criteria it reads this as 1 large criteria. I need to convert the text for the criteria box so that it recognises the OR statements and views this as 3 criteria elements rather than 1.
Any ideas?

Thanks,
Gary.
 
Perhaps you could change the textbox to read:
"apple","orange","pear"

And then use some code:
Code:
Dim strSQL
Dim qdf As QueryDef

Set qdf = CurrentDb.QueryDefs("[i]qryQuery[/i]")
strSQL = "SELECT * FROM [i]tblTable[/i] WHERE Description IN ( " _
    & Me.[i]txtTextBox[/i] & ")"
qdf.SQL = strSQL
DoCmd.OpenQuery qdf.Name
 
You can set up a query with no coding like:

SELECT *
FROM tblCustomers
WHERE Instr("," & Forms!frmSetCrit!txtCities & ",", "," & [City] & ",")>0;

This would expect entries into the text box like:
New York,Los Angeles,Chicago

There is some generic multi-select listbox code at
Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top