This one is difficult to explain, so I will cut it down to the basics.
I have a major table 'tblA' which has an autonum field 'ID-A' as primary key
(of no significance to users). 'tblA' contains many fields including
picture and memo fields. The main user-selectable field is 'NameA'.
There is also a crossreference table (let's call it 'tblB') which provides a
secondary method of accessing records in 'tblA'. The main fields in 'tblB'
are an autonum primary key 'ID-B', a field 'ID-A" corresponding to the
related record in 'tblA', and the alternative user-selectable field 'NameB'.
The main form is 'frmA' in which the user can review and/or update
individual records in table 'tblA'. There is also a search form 'frmS' in
which the user can specify a name or partial name ('txtName') which will
match a record either directly in 'tblA' or via a crossreference in 'tblB'.
If you are still with me, the idea is that the user will enter a (partial)
name in form frmS and a search will be made of both tables 'tblA' and
'tblB', with the end result being a set of records from 'tblA' that match
either directly or via a crossreference. The SQL will be passed to form
frmA as its RecordSource. The user can navigate through the list to review
or update records using the navigation buttons at the bottom of the form.
This is the SQL I am currently using:
"SELECT tblA.*
FROM tblA LEFT JOIN tblB ON tblA.ID-A = tblB.ID-A
WHERE tblB.NameB LIKE '" & txtName & "*'
UNION ALL SELECT tblA.*
FROM tblA
WHERE tblA.NameA LIKE '" & txtName & "*'
ORDER BY ID-A;"
The first part of the query looks for a matching crossreference in tblB and
outputs the corresponding tblA record. The second part looks for a direct
match in tblA.
I have two problems with this:
1) The use of UNION ALL seems to make the query read-only, even though only
tblA columns are output. This prevents the tblA records in frmA from being
updated.
2) It is possible for two or more hits to occur on the same tblA record --
one direct hit and one crossreference hit. Also two different (but
partially matching) crossreference hits. I would like the final output
passed to frmA to have include only one reference to each tblA record (so
that the user does not get the same record more than once when navigating
through the list).
I hope that this makes sense. It is a cut-down version of the actual setup.
As a workaround, there is a third, intermediate form which displays the list
of matching records from the search -- the user can select one and carry
that single record to frmA. But to navigate to the other records in the
list requires the user to close frmA, go back to the intermediate form,
select the next record, and then open frmA again for that record. Very
tedious, and something I would like to avoid.
Any suggestions? Please??? Problem 1) is the main one -- I need to be able
to update the set of records pulled from tblA either directly or via
crossreference. Problem 2) is to avoid user confusion where they navigate
the same record more than once (and to make the solution neater).
TIA.
--
Cheers,
Lyn.