Thread: Table Design
View Single Post
  #2  
Old April 27th, 2005, 04:28 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Sun, 24 Apr 2005 19:36:05 -0400, wrote:

I have a table for Equipment in a plant that contains all information about
the machine in general such as Production Number, Serial Number, Date
Purchased ect. Each machine has several sections that make up the whole such
as Feed section, Print Section and Cut Section. I want to have the main
machine with a number such as 123.000 and each part to list under that
machine such as (Feed) will be 123.001 and so forth. Each parent machine
already has an Equipment ID number that is an auto-number (existing DB) so
that ID 1 will be machine 123, 2 will be another machine. Is there a way to
"nest" the child machine under the parent without creating a table for each
section and each machine?


This should be stored in TWO fields, not in one. If the main machine
is 123, then the child machine table should have a foreign key to the
EquipmentID field (containing 123), and a *SEPARATE* field ComponentNo
let's call it; this should be a simple Long Integer number field.

To populate it, use a Form to do your data entry; base the Form on the
Equipment table and a Subform on the Components table. In the
subform's BeforeInsert event put code like

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ComponentNo = NZ(DMax("[ComponentNo]", "[Components]", _
"[EquipmentID] = " & Me!EquipmentID)) + 1
End Sub

This will look up the largest existing component number for this
EquipmentID (and the NZ() function will return 0 if there are no
components entered yet), add one, and store that value.

You can concatenate the two fields for display purposes using an
expression like

[EquipmentID] & "." & Format([ComponentNo], "000")

John W. Vinson[MVP]