Tim:
To return the names in a query you need to join the tblProductionOperation
to three instances of the tblEmployees table in the query. The joins are on
EmployeeID and SetupPerson, Operator1, and Operator2 respectively. You can
then return columns which show the names for each. Lets assume that the
employees table includes columns FirstName and LastName, and that the first
instance of the employees table you added to the query is joined on the
SetupPerson column, in query design view for the setup person you'd enter
this in the 'field' row of a blank column in the design grid:
[Setup Person]:[tblEmployees].[FirstName] & " " & [tblEmployees].[LastName]
When you add more than one instance of a table to a query Access gives each
instance a _1, _2 etc suffix, so assuming the second instance is joined on
Operator1 the expression for another computed column would be:
[Operator 1]:[tblEmployees_1].[FirstName] & " " & [tblEmployees_1].[LastName]
and for that joined onOperator2:
[Operator 2]:[tblEmployees_2].[FirstName] & " " & [tblEmployees_2].[LastName]
In a form you'd do it in a different way. Ther is no need to join the
tables in a query; the form would be based on the tblProductionOperation
table or a query based solely on that table, and in the form the controls for
the SetupPerson, Operator1, and Operator2 fields would be combo boxes. These
would be set up with properties like so:
RowSource: SELECT EmployeeID, FirstName & " " & LastName AS FullName
FROM tblEmployees ORDER BY LastName, FirstName;
BoundColum: 1
ColumnCount: 2
ColumnWidths 0cm;8cm
If your units are measurement are imperial rather than metric Access will
automatically convert the last one. The important thing is that the first
dimension is zero to hide the first column and that the second is at least as
wide as the combo box. You'll see the names ordered alphabetically by last
name then first name, but the values of the combo boxes will be the hidden
first columns.
Having said that, there is in fact a design flaw in your table. Having
multiple columns refereeing the employees table is what's known as 'encoding
data as column headings', whereas in a relational database data should only
be stored as values at column positions in tables; what's called the
'information principle'. What you have here is a many-to-many relationship
between tblProductionOperation and tblEmployees. The correct way to model
such a relationship type is by a third table. This would have two foreign
key, one referencing the primary key of tblProductionOperation and the other
the primary key of tblEmployees. It would also have a column, e.g.
EmmployeeRole which would contain values "Set up person" or "Operator" as
appropriate. Consequently ther would be three rows in this table for each
row in tblProductionOperation, assuming one set up person and two operators.
You could of course add more operators per row in tblProductionOperation if
you wished simply by inserting more rows into the table. Data input for
tables like this which model a many-to-many relationship is normally done via
a subform; the order details subform in Northwind is an example of this.
Whether you decide to change your design is you to you of course, but even
if you don't, be aware that it is faulty and could give rise to problems
querying the database at some stage; not insurmountable ones, but which could
require a bit of ingenuity to work around the flaw in the logical model.
Ken Sheridan
Stafford, England
Create a continuous view form based on the query...........
Hi Ken,
I've tried it the way you suggested and I like it a lot. I've also
tried creating an unbound dialog box that accepts my 3 criteria and
when the user clicks a command button on this form it does
DoCmd.OpenQuery. This is the method I was trying to get away
from...however....now that you've introduced me to some of the finer
points of the Query Desgn interface I think it might actually be
advantageous to go that route. The design interface and the datasheet
view are much more flexible format-wise than I had originally thought.
I am stuck on one thing however.
I have three fields in tblProductionOperation that are all linked to
tblEmployees.EmployeeID (autonumber PK). The three fields are
SetupPerson, Operator1, and Operator2 (When I setup my relationships I
simply dragged an instance of EmployeeID onto each field in the other
table). When my query runs these three fields each return a numeric
value (EmployeeID). I would like to view the employee's name
concatenated rather than a number - and I am sure this is simple but I
can't figure it out.
I was looking at the Northwind Orders Query trying to figure out how
they concatenated the Employee names in that query to no avail. I
tried looking at all of the Properties pages I could find. I've read
the SQL behind the query, etc. I can't find anything that looks like
[Last Name]&", "&[First Name] which is how it appears they
accomplished this but I just can't find it. I've read that that last
expression could be used to define a new field but I do not see how
they accomplished that in the Northwind db. I've got the books out
but ................
Thank you again,
Tim