Megan said:
Hi,
I am VERY new to Access and trying to do something way beyond my
skills.
Can anyone help me out with the Afterupdate event?
I have a table called equipment_name that has separate columns for the
equipment name, description, and manufacturer. I have another table
called equipment that has this list, plus other information about
specific pieces of equipment (the serial number is the unique
identifier).
I would like to have a form for the equipment that when you enter in
the equipment name, the description and manufacturer automatically
fill in. That way mistakes will (hopefully) be limited. If I can
"fix" those so they cannot be changed as well, that would be good.
You shouldn't have the equipment description and manufacturer in both
tables. From your description, there seems to be a one-to-many
relationship between [equipment_name] and [equipment] -- for each record
in [equipment_name], there may be many records in [equipment] that have
that same information. So all you should store in [equipment] is the
primary key value of the related [equipment_name] record. (On a form,
you can use a combo box based on [equipment_name] to look this up.) You
don't need an AfterUpdate event to look up the various fields from the
[equipment_name] table and stuff them into corresponding fields in the
[equipment] record, because such corresponding fields don't even exist.
This is the best way to avoid mistakes and discrepancies in such
relationships.
But you probably still want to show those fields on your Equipment form,
so the user can see what they are. There are two ways to go about this:
(1) Use an "autolookup query".
Base the form on a query that joins the two tables on the key field that
relates them. Have the query include all the fields from [equipment],
and those fields from [equipment_name] that you want to show, and put
all those fields on your form. As soon as you choose a the equipment
name for a particular equipment record, the description and manufacturer
will automatically fill in.
Note that these fields will (normally) be updatable, and if you update
them on the form for one record, you're updating them for all records
with that equipment_name. That's because you're actually modifying the
equipment_name table in that case. If you don't want them to be
updatable, set the text boxes' Locked property.
(2) Pull data from the combo box.
Alternatively, you can base the form solely on the [equipment] table,
but collect the extra informatin from the [equipment_name] table in the
combo box. Let the combo box have a rowsource that includes the extra
columns from the table, and then have calculated text boxes on the form
that use controlsource expressions to pull the description and
manufacturer from the Column property of the combo box.
So, for example, if your [equipment_name] table has fields like this:
EqName (primary key)
Description
Manufacturer
.... then you'd set your combo box (maybe named "cboEQName") with these
properties:
Row Source:
SELECT EqName, Description, ManufacturerFROM [equipment_name];
Column Count: 3
.... and you'd have text boxes on your form with controlsources like
these:
=[cboEQName].[Column](1)
=[cboEQName].[Column](2)
Note that .Column(1) is actually the second column in the combo box,
because the columns are numbered starting from 0.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)