LFC said:
My tables represent, warranty data, problems at the factory and more
failure
data. Unforunately there are multiple occurances of serial numbers in all
3
tables so the relationships are many-to-many...I know this isn't a good
thing, but I didn't know what else to do. Essentially what I want is to
be
able to see all cases of a serial number being involved in all three
because
it should help us improve quality if we can identify a reocurring problem
over all 3 tables. I also found out that in one of my tables the the
first
digit and the last 4 digits of some serial numbers were not entered. I
think
that means I need to change to a like condition, but when I wrote it up I
return no results.
SELECT QIT_LWH_IMP_tbl.PIN, QIT_LWH_IMP_tbl.[Build Date],
QIT_LWH_IMP_tbl.[Claim Number], QIT_LWH_IMP_tbl.[Part Number],
QIT_LWH_IMP_tbl.[Failure Mode Code], QIT_LWH_IMP_tbl.[Failure Reason Code]
FROM QIT_LWH_IMP_tbl, QIT_DTAC_IMP_tbl, QIT_Z3_QNOTE_tbl
WHERE (((QIT_LWH_IMP_tbl.PIN) Like '*QIT_DTAC_IMP_tbl.PIN*' And
(QIT_LWH_IMP_tbl.PIN) Like '*QIT_Z3_QNOTE_tbl.[Serial Number]*'));
Hmm, to see all cases from all tables in one list, you're going to have to
use a union query, and a union query can't be updatable. Therefore, I think
I would do something like this:
1. Create a union query to get master list of all serial numbers in all
tables. Let each record in the union query also include a calculated field
identifying which table it comes from. Use UNION, not UNION ALL, so that
there will be only one record returned from each table for any given serial
number. (I'm going to assume for now that you don't care if there are
multiple records for the same serial number in one table; only if there are
records for that serial number in two or more of the tables.) The SQL might
look like:
SELECT PIN As SerialNo, "L" As SourceTable
FROM QIT_LWH_IMP_tbl
UNION
SELECT PIN As SerialNo, "D" As SourceTable
FROM QIT_DTAC_IMP_tbl
UNION
SELECT [Serial Number] As SerialNo, "Z" As SourceTable
FROM QIT_Z3_QNOTE_tbl
Suppose we save this query as "qryAllSerialNos".
2. Create a query that selects from the union query above, only those
records that have matching records from one of the other tables. It might
have SQL like this:
SELECT * FROM qryAllSerialNos
WHERE
(SourceTable = "L" AND
Exists(
SELECT PIN FROM QIT_DTAC_IMP_tbl
WHERE PIN = SerialNo
)
OR
Exists(
SELECT [Serial Number] FROM QIT_Z3_QNOTE_tbl
WHERE [Serial Number] = SerialNo
)
)
OR
(SourceTable = "D" AND
Exists(
SELECT PIN FROM QIT_LWH_IMP_tbl
WHERE PIN = SerialNo
)
OR
Exists(
SELECT [Serial Number] FROM QIT_Z3_QNOTE_tbl
WHERE [Serial Number] = SerialNo
)
)
OR
(SourceTable = "Z" AND
Exists(
SELECT PIN FROM QIT_LWH_IMP_tbl
WHERE PIN = SerialNo
)
OR
Exists(
SELECT PIN FROM QIT_DTAC_IMP_tbl
WHERE PIN = SerialNo
)
)
That's pretty hairy, and I don't know how efficient it will be, but it might
work. If any "Like" comparisons need to be done, they can be put in later,
but I'm interested to see if this approach works.
Save that query as "qrySerialNosMultiple".
Now, opening that query all by itself should show you what serial numbers
are problematic, and what tables they're in. But if you want to be able to
update the records or see the detail of each, that approach is too
simplistic. For that, I think I would proceed as follows:
Put a list box on an unbound form, and set the list box's rowsource to
qrySerialNosMultiple. Let the list box have two columns, one for SerialNo
and one for SourceTable, and let the SerialNo column be the list box's bound
column.
Put three subforms on that form, one bound to each of the three tables, each
subform set in continuous forms view (or datasheet view). Set the Link
Master Fields property of each subform control to the name of the list box.
Set the Link Child Fields property of each subform to the name of the
serial-number field in that subform's recordsource table -- PIN or [Serial
Number].
Now, whenever you click on a serial number in the list box, you'll see the
matching records, if any, in each of the subforms. That will let you decide
what to do about them, and potentially do it on the spot.