Do those 'many' tables have primary key fields of their own? Is that the
[taskID], [hazardID], and [hazmatID]?
What data type is the jobTbl!formID? What data type(s) are the [formID]
fields in the 'many' tables?
Here are some issues/questions you'll want to address before using the SQL
statement (adapted by you for your specific situation):
* The field names "Date" and "Name" in your [jobTbl] are reserved words in
Access. What YOU mean and what Access believes they mean may not match.
Please note that I've changed these fieldnames in the SQL below.
* the [subTasksTbl) appears to only have ID fields ... where's the
'beef'?!
If I wanted to present all of the information (which will, remember, be
"duplicated" for the "one" table), and bearing in mind that the "many"
tables may or may NOT have related records, I would use something like
(untested aircode - adapt as needed):
SELECT jobTbl.formID, jobTbl.FormDate, jobTbl.FormName, jobTbl.jobDescript,
subTasksTbl.taskID, hazardsTbl.hazardID, hazardsTbl.Description,
hazmatsTbl.hazmatID, hazmatsTbl.productlist, hazmatsTbl.MSDS
FROM ((jobTbl LEFT JOIN subTasksTbl ON jobTbl.formID = subTasksTbl.formID)
LEFT JOIN hazardsTbl ON jobTbl.formID = hazardsTbl.formID) LEFT JOIN
hazmatsTbl ON jobTbl.formID = hazmatsTbl.formID;
Regards
Jeff Boyce
Microsoft Office/Access MVP
howie said:
Fair enough...
jobTbl
formID
Date
Name
jobDescript
subTasksTbl
formID
taskID
hazardsTbl
formID
hazardID
Description
hazmatsTbl
formID
hazmatID
productList
MSDS
ok, here's a sample of the database that I am creating. For every one row
in
jobTbl there can be many rows in subTasksTbl, hazardsTbl, and hazmatsTbl.
Thanks Jeff
--
howie
Jeff Boyce said:
Let's trade ...
You give me a description of a couple of tables related one-to-many from
your domain, I'll take a stab at a query that provides the user all
information from both tables.
For example, a school registration db might have:
tblStudent
StudentID
FName
LName
tblClass
ClassID
ClassTitle
ClassDescription
trelEnrollment
EnrollmentID
StudentID
ClassID
EnrollmentDate
Regards
Jeff Boyce
Microsoft Office/Access MVP
Can you give me an example of a "flattening" query?
--
howie
:
Because it would "flatten" the data, a one-to-many relationship would
'repeat' the one information for each of the many rows.
Regards
Jeff Boyce
Microsoft Office/Access MVP
I see what you mean now.
How would I deal with the one-to-many relationships though? I think
i've
written a query like this before, maybe it wasn't flattening as much
as
selecting everything but it turned out like below. Every time I had
more
than
one entry in a table, the whole set of data for that form id would
be
printed
for each different hazard, and so on for each of the other tables.
Example:
FormID Name Job Task Hazard
Sub-Task
1 Bob something falling objects
Climbing
Ladder
1 Bob something flying objects
Climbing
Ladder
1 Bob something falling objects
manual
lifting
1 Bob something flying objects
manual
lifting
The cross product of all the tables would be huge even with a
relatively
small number entries.
--
howie
:
I'm suggesting not requiring the user to ever know or see a FormID.
If you join together all the tables that have related information
(in
a
query), then give the user a way to search against that query, s/he
should
be able to find the information without ever touching a FormID.
(a "flattening" query ... that may not be a real term ... joins all
the
tables together, so the user sees something like what you'd have if
you
lined up all the data in a wide spreadsheet. The term "flat" is a
distinction from what you have with a relational design (deep, not
wide))
Regards
Jeff Boyce
Microsoft Office/Access MVP
Jeff,
Can you explain a little bit what you mean? Especially a
"flattening"
query.
The term sounds kind of familar, but it's not ringing any bells.
Are you talking about giving the user a way to basically look up
say
the
formID using some other piece of data?
--
howie
:
Howie
Another option would be to create a "flattening" query that
joins
all
that
related information together, then give the user a way to look
up
information from THAT query.
This way, the user isn't exposed to and doesn't have to learn
"relational
database design".
Regards
Jeff Boyce
Microsoft Office/Access MVP
Thanks Jerry! That sounds great. But I want to get real fancy
with
it
and
make that form so that the user can choose from a combo box,
fields
like
name, date or formid and then provide that data and the report
will
be
generated. Is there any way to do that?
The reason that I ask is because I am making this database for
someone
else
at my job, and they don't like that all the information is
tied
to
the
formID
(they don't understand how relational databases work) so they
want
to
be
able
to search based on the name, the date, the job task, the
division,
or
the
job
task. Is there anyway to do that? Because there is the
possibility
that
they
can get multiple sets of results from searching for something
besides
the
formID. So I didn't know if I would be able to allow them to
look
at
the
report without knowing the formID of the set of data they want
to
fill
the
report.
--
howie
:
Create an unbound form called something like: frmParameter.
On this form put text fields something like [txtParameter],
[txtParameter2],
etc. for all the needed criteria/parameters.
Next put a command button on the form that runs the report. A
nice
touch
would be to have the form also go invisible as it needs to
stay
open
for
the
report to run.
Now the magic part! Put something like below in the query
criteria
as
needed
with the proper form and text box name.
[Forms]![frmParameter]![txtParameter]
Now instead of getting bothered with multiple requests for
parameters,
it
will be on the form. If you need to run it again, the stuff