473,386 Members | 1,734 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,386 software developers and data experts.

Inserting new data within related tables inside Access

Hi All,

I need to insert new records in existing Tables of Access. The two tables are related by Primary and Foreign key relation. The new data to be imported is in Excel sheet which I have imported into new table.

Now,

Some columns needs to be inserted into Parent table and some would be inserted to child table.
The parent table has an automatically incremented ID column which is foreign key for the child table.

The insert into Parent table works fine but nothing's happening when I try to append records to the child table.
I used this query to insert values into child tables foreign key from parent tables primary key.
No-Luck. :(
INSERT INTO ChildTable(FID)
SELECT ID
FROM Parent table
WHERE ID > 4430

NOTE: 4430 is the last number that existed in both tables before my inserts to the Parent table.

Can anyone help me ?

Thanks very much !!
Jan 18 '10 #1
9 6670
nico5038
3,080 Expert 2GB
This can only be realized with an "external" ID linking the original Parent to it's Children.
Adding the Parent will also require the addition of the "additional" "external ID" to the Parent table.
Now the children can be added extracting the autonumber of the Parent found using this "external ID".

Getting the idea ?

Nic;o)
Jan 18 '10 #2
Not really !
Let me explain what I understood.
Table1 (parent)
ID1 A B C

Table2(Child)
D E F ID1 ID2
So, I have to add an auto increment column say(ID3) in both the tables?
Then, insert new records in Table1.
After this operation ID1 gets populated by new values. Then what would be the next step?
Use ID3 values to get values in field ID1(table1) and insert them in ID1(table2) using ID3?
and then insert rest of the data in table2?
I appreciate you reply.:o)
Thanks !
Jan 19 '10 #3
nico5038
3,080 Expert 2GB
Input table data:
Table1 (parent)
ID1 A B C

Table2(Child)
ID1(FK) ID2 D E F

Database tables:
Table1 (parent)
NewID1 A B C OldID1

Table2(Child)
NewID1(FK) ID2 D E F

It's assumed that the ID1 from the input is stored in OldID of the parent table. The NewID (autnumber) needed for adding the child, can than be "extracted" by using the ID1 from the input to extract the NewID from the parent they belong to.

The OldID could be emptied or removed after the import, as after adding the children it's no longer needed.

Nic;o)
Jan 19 '10 #4
Thanks very much !! Nic,
I'll try your solution and post back with the results.

Kind Regards,
Trueman
Jan 19 '10 #5
Hi Nic,
I used this query to insert records into child table
Insert into Child(Field5, Field6, ID)
From Import inner join Parent on
Import.Field1 = Parent.Field1and
Import.Field2 = Parent.Field2
Thanks !!
Trueman
Jan 22 '10 #6
nico5038
3,080 Expert 2GB
I see you got the message :-)

Success with your application !

Nic;o)
Jan 22 '10 #7
Nic,
Can you take stab on this one please?
UPDATE tblA
SET tblA.Field0 = tblB.Field0,
tblA.Field1= tblB.Field1,
tblA.Field2= tblB.Field2,
tblA.Field3= tblB.Field3,
tblA.Field4= tblB.Field4,
tblA.Field5= tblB.Field5 FROM tblB INNER JOIN tblA ON tblB.[PrimaryLocation] = tblA.PID;
Error: missing operator in expression 'tblA.Field5=..............=tblA.PID'

Just trying to update certain records in one table based upon corresponding records from another table.
In some another forum I got the idea of using DLOOKUP and I'm looking into that as well.

Kind Regards,
Trueman :)
Jan 22 '10 #8
nico5038
3,080 Expert 2GB
You could probably use:
Expand|Select|Wrap|Line Numbers
  1. tblA.Field5 = (SELECT tblB.Field5 FROM tblB WHERE tblB.[PrimaryLocation] = tblA.PID)
  2.  
This should be faster as the DLOOKUP() function that's rather "slow".
Another (faster) solution could be to perform first a DELETE * from all unique ID's in tblA that also resides in tblB and than Append tblB completely.

Nic;o)
Jan 22 '10 #9
Thanks very much !!

Both of the ways work good. I was using 'from' clause in my update query hence syntax error.
Removing that and rearranging the query yielded results. :)


Regards,
Trueman
Jan 23 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jan Willems | last post by:
Hi, We use a database with about 40 related tables. Some tables contain as much as 30.000 records. We use Access97 as an interface to the database. Now recently we have the problem that when we...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
5
by: jqpdev | last post by:
Hello all... I'm coming from a Borland Delphi background. Delphi has a specific component called a Data Module. In the designer the Data Module behaves like a windows form. A developer can...
2
by: Jim in Arizona | last post by:
Usually, If i need special formatting, I don't use the datagrid control and use a loop that processes a table for each record read from the database (as in classic asp) like so: ...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
2
by: Sridhar | last post by:
Hi, I am trying to implement sql transactions. But I am not knowing how to do that. I created a data access layer which contains methods to select/insert/update tables in a database. I have also...
5
by: Will | last post by:
- I know enough ASP and Access to be dangerous :) - I need to put up a data base on our web server with 3 related tables. - They will be accessed by a limited number of people. - Each user will...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.