Colm O'Hagan wrote:
Hi there,
I having a problem with a database I'm setting up, I would be
delighted if someone out there could help.
The database I'm setting up is a task register datebase, it will be
used to create work schedules for workers in a metal work shop, based
on the tasks required to make a part and the tasks required to make
the subcomponents of the part.
In the DB I have three main tables; the first table is called Parts
with a related table called SubComponents the third table is called
Tasks. I want to be able to select a record from the Parts table and
add it and its related records from the SubComponents table to the
Tasks table. The desired result is to have a list of all tasks that
need to be completed to make the required parts and their sub
components.
Could anyone advise me on how to achieve this?
Thank you in advance,
Colm
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.