473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
2 3022
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
1
by: Dave | last post by:
I have a form which is based on a table (a) with over 6000 records.I have a button on this form which will open another form with related data from another table (b). What I want to do is open the...
2
by: Colm O'Hagan | last post by:
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...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
12
by: jaYPee | last post by:
I have currently using a dataset to access my data from sql server 2000. The dataset contains 3 tables that is related to each other. parent/child/grandchild relationship. My problem is it's very...
2
by: jaYPee | last post by:
I have no problem setting the selectcommand in sqldataadapter to fetch record from sqlserver w/ where clause in parent table. however, my problem is on how can i fetch the child table which is...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
4
by: jbrumbau | last post by:
Hello, I have been successfully using a database I've created for several months to populate an equipment list for a project we've been working on. However, the form has recently stopped working...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.