Re: Print Form/Report with Master and one Detail record per page?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chuck (anonymous_at_discussions.microsoft.com)
Date: 02/16/04


Date: Mon, 16 Feb 2004 15:23:21 -0800

Thanks 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
                   MasterTable.MasterTableKey =
DetailTable.MasterTableKey
WHERE DetailTable.Primarykey.Skey = MasterTable.Skey and
DetailTable.Primarykey.Srt = 1

This would be in my case:

SELECT * FROM tblSWChngNotice INNER JOIN tblSCNdata ON
tblSWChngNotice.Skey = tblSCNdata.Skey
WHERE tblSCNdata.Skey = tblSWChngNotice.Skey and
tblSCNdata.Srt = 1

Now that I've re-thought this, with your help, I think it
should work as you suggest with creating a query with just
the selected records to be printed.

I have to give it some thought on how to make it an
automatic printout using a form. I will probably need to
create a report and print each record on a different sheet
to make it automatic.

I will check the SQL format and try to implement this (by
the end of this week) and see if it works. Or I may use
the Query Designer to create the query.

Thanks again Rod.

Chuck

>-----Original Message-----
>Chuck,
>
>Sounds rather complex and I don't understand all the
details but:
>
>The JOIN query should still work because the link between
the master and
>detail records only depend on the common value of the
master key in both
>tables.
>
>A join such as
>
> SELECT * FROM MasterTable INNER JOIN DetailsTable ON
>MasterTable.MasterTableKey = DetailTable.MasterTableKey
>
>Should give you all data from the details table along
with all data from the
>corresponding master table.
>
>Adding a WHERE clause to the above should allow you to
select the relevant
>records in the same way as you select them now. I
suspect it is the way you
>select them now that I'm not understanding
>
>You could try explaining it again using smaller words and
I might finally
>get it.
>
>Rod Scoullar
>
>
>.
>



Relevant Pages

  • Re: Print Form/Report with Master and one Detail record per page?
    ... For the purpose the forms were designed for, the subform ... worked correctly showing all detail records for any master ... I did not have a query ...
    (microsoft.public.access.formscoding)
  • Re: BIG BUG in Deleting detali records
    ... You could write a trigger on the master table to ... I think the updatebatch work wrong on deleting datil records ... ... happen deleting master record does not delete detail records after ...
    (borland.public.delphi.database.ado)
  • Re: SQL Statement for limiting the number of detail retrieved in Access 2000?
    ... Hexman wrote: ... INNER JOIN ... How do I limit the number of detail records selected in a Master-Detail set using SQL? ... I want to select all master records for a date, but only the first 3 records for the details. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SQL Statement for limiting the number of detail retrieved in Access 2000?
    ... Hexman wrote: ... INNER JOIN ... How do I limit the number of detail records selected in a Master-Detail set using SQL? ... I want to select all master records for a date, but only the first 3 records for the details. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Opinions needed about the best "Middleware suite" kbmMW vs. RODA
    ... >> record it deletes all detail records, and of course when you apply the ... >> updates to the database, it deletes first the detail records then the ... > I am not sure why you wouldn't want to have the posted in one transaction, ... when the primary field of the Master table is an identity field, ...
    (borland.public.delphi.thirdpartytools.general)