Click to See Complete Forum and Search --> : Query Techniques - Access DB


FrozenPixel
November 16th, 2006, 03:59 PM
Hello all,

I didn't know where to get this answer if in fact there is an answer so I am assuming I have found a good source of knowledge based on the amount of members and quality content, so here goes.

Is it possible, in Access, to create a query that allows an end user to add multiple strings in order to search and return all the records that match at least one of the search strings.

This is an example of the problem. Say the database was created so that a person was to have one or more skills and /or NOC codes(National Occupation Code). So for instance if:

Person A: 1234, 3456, 7890

Person B: 3456, 7654

Person C: 1234

The person would be assigned numerous NOC codes based on skills and what I would like to do is create a query that lets me enter a few, at least, NOC codes, but if I choose to only add one number the query would still work.

Back to the scenario, if I entered 1234 and 7654, records A-B-C would all be returned. I apologize if I am asking too much for you all here or being too vague. I personally normally would create my SQL string using forms in VB but I am trying to help out a fellow worker who is getting so stressed because they are expected to complete this operation in Access alone and honestly I am not to familiar using the query builder in Access and unfamiliar with its strengths/weaknesses.

Any help, suggestions or comments would be greatly appreciated. I have an idea this can be done but I have been unsuccessful trying to find an appropriate solution up to now.

Thank you. I truly hope I have made sense.

davide++
November 17th, 2006, 03:37 AM
Hi all.

If the informations are stored in only one table (as I believe), probably your database isn't well designed.
You should have two related tables, PERSONs and NOCS, and a field that links one record of PERSONS to many records of NOCS (1-n relationships). For example:

Table PERSONS
ID_PERSON NAME
1 PERSON A
2 PERSON B
3 PERSON C

Table NOCS
ID_PERSON ID_NOCS
1 1234
1 3456
1 7890
2 3456
2 7654
3 1234

Now is very easy to find all person starting from NOCs; for example the query


SELECT P.NAME
FROM PERSON P, NOCS N
WHERE N.ID_PERSON = P.ID_PERSON
AND ID_NOCS IN (1234, 7654)


will extract all three persons

FrozenPixel
November 18th, 2006, 03:18 PM
Hello, the database is set up to associate the NOCS with PersonID but the problem is using only Access's query builder to give the user that option of adding more than one search string. This is where the problem lies.