View Full Version : !!! How to create this Query?


prometro
12-08-2007, 02:10 PM
In database is one Table, where are only two fields (ID and Text):
ID Text
1 AA
2 BB
3 AA
4 CC
5 EE

And in a form I have TexBox where is a text string, for ex. : aa; cc; ee
Im trying to create Query which find all records from Table which contains
"aa" or "cc" or "ee".

If I use concrete values in Query, it works :
SELECT * FROM Table WHERE (((Table.text) In ("aa","cc,ee")));
but when I use refer to a TextBox it doesn't works :(:
SELECT * FROM Table WHERE (((Table.text) In ([TexBox])));
Because it will do [TextBox]="aa;cc;ee" and not "aa";"cc";"ee"
Can anyone help me with it?
Thank you and have nice day.
Jira

Uncle Gizmo
12-09-2007, 12:59 PM
Your question is not quite clear so I am assuming that you want to check for this: "aa";"cc";"ee"

It appears you are using "In" to check for all three at one go, interesting, I hadn't thought of doing that.

The first thing I would consider is having three text boxes one for each entry, and then re write your query something like:

SELECT * FROM Table WHERE Table.text = Me.TexBox1 or Table.text = Me.TexBox2 or Table.text = Me.TexBox3

n123456
12-09-2007, 01:04 PM
Or you could use a listbox and then create your SQl dynamcal with the values choosen in the listbox.

Uncle Gizmo
12-09-2007, 01:44 PM
Yes that's a good idea n123..., I don't normally replied to replies, but I thought it worth mentioning I am currently trying to put together a class module to make this a simple matter, however it's not quite finished yet.

Uncle Gizmo
12-09-2007, 01:57 PM
Correction it's a function, I just had a look, it's a project I was working on a couple of months ago and I haven't finished yet, well that's my excuse for getting it wrong anyway!

On the other hand I may turn it into a class!

prometro
12-12-2007, 07:00 AM
Thank you for reply very much - yes maybe I didnt explain my question well - but my english is not the best you know:)
So to explain my problem I drew small picture.
Please look at it and if you will know how to do it please reply.
Thank you Jira

neileg
12-12-2007, 07:42 AM
Another way is to populate a temporary table from the listbox and join this to the original table in a query.