Can I add records form a table and related records another table to a third table?

Can I add records form a table and related records another table to a third table?

Post by Sala » Sun, 04 Apr 2004 15:45:55



If you have a Parts table and Sub-Components then then if you pass the
PartNo (whatever is your primary key) then the task record would have
access to all of the information on that part. IOW, simply append the
PartID to the task record.

Let's say a part has 3 components. Would that be 3 tasks? If so, you
would then want to add the component key to the task record...it
wouldn't be necessary to add the Parts key.

PartsTable
PartID
PartDescription
SubParts
SubPartID
PartID
SubPartsDescription

Tasks
TaskID
SubPartID
Date....

You can link back based on the subpartid to the subparts table that will
link you to the parts table.

You can add the record via an append query. See Append Query in help.
Also look at the Execute method in help.

You can add via a recordset. Using DAO (code similar to below would be
added in an event procedure under the button or control that would add
the record)

Dim strSQL As STring
Dim rst As Recordset
Dim rstTask As REcordset

Set rst = Currentdb.Openrecordset("Tasks",dbopendynaset)

strSQL = "Select SubPartID From SubPart Where " & _
"PartID = " & Me.PartID
set rst = currentdb.openrecordset(strSQL,dbopensnapshot)
If rst.RecordCount > 0 then
Do while not rst.Eof
rstTask.AddNew
rstTask!SubPartID = rst!
rstTask.Update
rst.MoveNext
loop
endif
rst.close
rstTask.close
set rst = Nothing
set rstTask = Nothing

The above selects all sub part records for the part number (Me.PartID)
that you have selected and loops through the set, adding a task record
for each subpart.

Is a part made up of subcoms or parts and sub coms separate units. If
so, you may want to have a task record that contains the part number and
have another table SubTasks that links to Tasks and then have each
part and all sub components in it with detail. You could put in a code
field like P for Part and S for SubComponent.

Setting up the task table correctly will be crucial to you if you want
this to succeed.