Solved

ADO AddNew to multiple tables!

Posted on 2006-11-10
11
491 Views
Last Modified: 2012-08-14
Hello,

I would like to create an ADO recordset that basically takes two tables and adds a row to each but I am unable to do this I get a "object or provider is not capable of performing..." error.

Can anyone tell me how to do this?

I want to do this because I have a form that is bound to 2 tables and I want to have a custom ADDNew option.

Basically something like this:

Dim rs As New ADODB.Recordset

rs.Open "SELECT * FROM Table1, Table2", cn,  adOpenKeyset, adLockOptimistic
rs.AddNew

ANY IDEAS WOULD BE GREATLY APPRECIATED.

Thanks

Mac
0
Comment
Question by:mac-will01
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 20 total points
ID: 17916945
A Recordset object can only be for one table, not two.

You can have a recordset object that runs a query with columns from two tables, but you can't use it to add records to two tables.
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17916950
"SELECT * FROM Table1, Table2",

this is a cartesian result and is simply not updateable, try opening each table seperately and doing the add
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17916968
If there are common columns in these tables, you can join them into one recordset object, but you won't be able to add records to both.

"SELECT Table1.*, Table2.* FROM Table1 INNER JOIN Table2 ON Table1.SomeID=Table2.SomeID"
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 30 total points
ID: 17916977
Why not two recordset objects rs1 and rs2 - and AddNew to both of them

Dim rs1 As New ADODB.Recordset, rs2 as ADODB.Recordset

rs1.Open "SELECT * FROM Table1, cn,  adOpenKeyset, adLockOptimistic
rs1.AddNew

rs2.Open "SELECT * FROM Table2", cn,  adOpenKeyset, adLockOptimistic
rs2.AddNew
0
 
LVL 1

Author Comment

by:mac-will01
ID: 17917291
Thanks guys,

I guess you are all saying I can't use AddNew when and ADO recordset has fields from multilple tables?

And as for GRayL's idea I have been tinkering with this but basically I am stuck with the following problem:
(P.S. I know this won't work)

Dim rs1 As New ADODB.Recordset, rs2 as ADODB.Recordset
rs1.Open "SELECT * FROM Table1, cn,  adOpenKeyset, adLockOptimistic
rs1.AddNew

rs2.Open "SELECT * FROM Table2", cn,  adOpenKeyset, adLockOptimistic
rs2.AddNew

Set Me.Recordset = rs1 + rs2  '?????

0
 
LVL 18

Assisted Solution

by:Data-Man
Data-Man earned 30 total points
ID: 17918360
What about Jim's comment about a join between the two tables.

If there is a join, then you could use a single recordset.

What are you trying to do?  I have found that executing an insert statement is faster than opening the recordset, adding a record and then closing it.

Is your data in SQL Server or just in Access?

Mike

0
 
LVL 1

Author Comment

by:mac-will01
ID: 17918614
Basically I have a form that cointains bound fields from two tables.  These two tables have a one-to-one relationship.  I would like to have a form to add a new entry into both tables.

As of now I am only using Access.
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 17918668
If the form is bound then adding data to the underlying tables should be automatic.  What is the Record Source property for the form?

Mike
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17919600
But what from rs1 and rs2?  Shouldn't it be something like:

Set Me.Recordset = rs1!fld1 + rs2.fld1
0
 
LVL 1

Author Comment

by:mac-will01
ID: 17919837
The SQL Record Source property for the form is quite complicated and is actually what is causing the problem.

I select ALL (*) fileds from 2 tables than 3 additional fields from 3 other tables that all optionally link in a chain from my main table.

Unfortunately I think I have to use an unbound form here, I just don't see anyway around it
0
 
LVL 1

Author Comment

by:mac-will01
ID: 17919844
Thanks for the help folks
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question