by Chuc » Wed, 18 Feb 2004 08:23:21
hanks Rod for the info. I think I understand the inner
join from your example. I hope I haven't confused you too
much. It is complicated to explain. I'll try again in
more detail.
I have a detail table holding records associated with the
master records. Initially it had no primary key.
Everything worked fine. Master/detail data was all printed
on one sheet even in the case of many detail records. Then
the user wanted to print master/detail data for specific
detail records on individual sheets of paper (for
documentation). Another change to the detail table
required adding three additional fields to allow the user
to enter data where one of the key fields allowed
duplicate data. This required making those fields into a
Primarykey to allow a detail record to be uniquely
identified. I initialized all required Primarykey fields
as needed by hand. Records where the Srt field in the
Primarykey = 1 are the detail records that need to be
printed.
My Detail table has a numeric key (Skey) which is the same
as the MasterTable, but it is Not THE primary key. The
Detail table has an additional key, a new Primary key,
involving four fields, including Skey. The detail record I
want printed out, along with the corresponding master
record data is the matching detail record where the Skey
field in the Primarykey = the MasterTable Skey field and
Srt field in the Primarykey =1. I want to print all such
records, if more than one. The way I figured out to do it
(although with problems) was to:
1) Select form (detail records bound to DetailTable query)
using the DoCmd.SelectObject
2) In Form_Load using recordsetclone, read a detail
record, in order (using movenext), where the MasterTable
key = the DetailTable key. An args value tells how many
movenext's to get to the next unique record.
3) Access prompts for the ProgramName (I have been unable
to eliminate the prompt)
4) The form is then filtered on that detail record after
entering the specified prompt value.
5) I exit the form (its still showing on the screen)
6) Using DoCmd.PrintOut , 1, 1. I print the form, then
unselect the form.
Note: I need the PrintOut, 1, 1 in case the user
cancels the prompt, to prevent printing all detail
records data on multiple sheets.
7) I loop back to select and open the form, and read the
next record and repeat the process, each time selecting
the next detail record for the selected master record.
There can be from 1 to many detail records for any master
record.
The user can view/change/add/delete detail records at any
time prior to printing. Now, because there is a multi-
field Primarykey, the appropriate Primarykey fields are
changed/initialized by code, using recordsetclone, at the
time of any change or creation of a new detail record.
This is done to manipulate the records to appear in a
specific meaningful order regardless of the user's actions
of creating or changing any detail records.
To print, the user should click a print key to print all
records that need to be printed.
If my code is correct, then specific, detail records (for
that master record) are the records I want to print (see
below).
I believe in order to follow your suggestion of using a
SQL INNER JOIN the needed SQL clause to select all
DetailTable Primarykey records to be printed would be:
SELECT * FROM MasterTable INNER JOIN DetailsTable ON
Maste