?
Solved

ADO AddNew to multiple tables!

Posted on 2006-11-10
11
Medium Priority
?
519 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 80 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 66

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 120 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 120 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

762 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