By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.


Nov 12 '05 #2

P: n/a
Hi Salad,

Thanks for the help. I putting it into action now.

I have one more related question.

I have a form with a subform. On the form I have a text box
'NoOfParts' I want to press a button and have the value entered in
this text box 'NoOfParts' to be copied to another text box in the
subform. If you could help me with the code for this I would be
delighted.

Thanks again,

Colm
Salad <oi*@vinegar.com> wrote in message news:<D4*******************@newsread1.news.pas.ear thlink.net>...
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.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.