What your report amounts to is a classic database problem, that of a 'Bill of
Materials' or 'Parts Explosion', so called because it commonly arises in the
context of assemblies which can be mad up of other assemblies and so on right
down to the base parts. Your scenario is analogous to this in than employee
reports to a manager, who in turn reports to another manager and so on.
Yours is in fact a much simpler model because one employee can only report
directly to one manager whereas an assembly can, and normally will, contain
more than one sub-assembly.
Because of the simplicity of your scenario it is in fact is a 'tree' (in the
mathematical sense) as it can be mapped out diagrammatically as a 'graph'
(again in the mathematical sense) in which there is only one path between any
two nodes, in the same way as there is only one path from a leaf on an oak
tree to the base of its trunk.
The most efficient way of modelling a tree is Joe Celko's Nested Set Model,
which he describes at:
http://www.intelligententerprise.com/001020/celko.jhtml
In fact the scenario he uses to illustrate it is an organisational structure
which closely parallels yours.
However, while I'd recommend you read Joe's article, I think you may find
implementing this a little beyond your level of experience, and you'd be
better off relying on the 'adjacency list' model, which is in essence what
Phil describes. Strictly speaking, as one employee reports directly to one
manager only you can do it all with one table, but using the separate
'adjacency list' table to model the relationship does have some advantages.
Note that the primary key of Phil's tbl_management table can be a composite
one of the emp-mgr, emp-sub and rel-begin columns, discarding the autonumber
column. If you do keep the autonumber column a unique index should be
created on these three columns (in conjunction, not individually). If you
are only modelling an emplyees' current position rather than there employment
history then the rel-begin column need not be part of the key.
When it comes to a query for your report things get tricky, because to cater
for an arbitrary number of levels in the hierarchy the query needs to be
recursive. However, no such animal exists as far as I'm aware. Recursive
querying is theoretically well covered in the literature, however, and it is
possible to simulate the steps involved. As it happens I did this once for a
magazine column written by a contact of mine, and the solution has very
recently been republished in a book celebrating 30 years of the magazine in
question. Unfortunately my file has long since disappeared from its web
site, but I can send you a copy direct if you mail me at:
kenwsheridan<at>yahoo<dot>co<dot>uk
The file which simulates the recursive querying probably won't be a lot of
use to you in fact, but Zipped with it is another 'PartsTree' file which does
produce a report in a horizontally oriented layout, which might well fit the
bill. This relies on a straightforward query which joins the adjacency list
table to itself a fixed number of times in LEFT OUTER JOINS. Consequently it
is limited to a fixed maximum levels of hierarchy, nine in fact. This
doesn't sound a lot but I'd imagine it will cope with most organisational
structures for which Access would be sensibly used.
Ken Sheridan
Stafford, England