Search from multiple tables

C

cmarsh

I want to search for records matching 2 fields in 10 tables. The 2 fields
are the same in each table, which are Accepted (Yes, No) and Project Name.
How would I create a report that will show data from all tables where the
Project name is selected and Accepted = either yes or no(whatever is picked
by user)?
 
D

Dale Fye

The easiest way would be if your data were properly normalized. If you have
10 tables with the same structure, you are doing something terribly wrong,
and should read up on data normalization and relational databases.

Having said that, you are probably stuck with what you have, so to work
around a bad situation, I would create a Union query. Which you can only do
by opening a new query (don't select any tables right now). In the upper
left corner of Access you should see a menu item that says SQL, click on
that. Otherwise from the database menu, select View, then SQL view.

Now you will have to create your query to look something like:

SELECT "Table1" as TableSource, [Project Name], [Accepted]
FROM table1
UNION ALL
SELECT "Table2" as TableSource, [Project Name], [Accepted]
FROM table2
UNION ALL
.... 'Repeat for each of the 10 tables
Union ALL
SELECT "Table10" as TableSource, [Project Name], [Accepted]
FROM table10

Save this query (qry_NormalizedData). Note that I have added the name of
the table that the data came from as a field (TableSource) in this query so
that you can identify which table the data came from.

Now, use this query as the source of another query.

SELECT TableSource, [Project Name], [Accepted]
FROM qry_NormalizedData
WHERE [Project Name] = Forms!FormName.txt_Project Name
AND [Accepted] = Forms!FormName.chk_Accepted

How you use this query depends on what you want to do with the data. You
could use it as the source for a report, or maybe for a subform.

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top