Solved

ADO Execute command

Posted on 2002-07-16
5
181 Views
Last Modified: 2010-05-02
I want to use an ADO "execute" command to add  new records into a talbe,something like this:

'presume I've already got a connection called cn
dim rs as Recordset
set rs=cn.Execute("insert into "Table1" (column1,column2) values ('something','and more')")

This command works fine for adding record to the table. Now, the problem is that I also want to use the rs which I expect to be a valid recordset returned by the command. But I always get a error message saying that "object is closed.".

Would anyone know what the problem is?
0
Comment
Question by:ChenChen
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7158339
because the INSERT statement is not returning a recordset.

a recordset is returned when you do a SELECT * FROM Table1.
0
 
LVL 4

Author Comment

by:ChenChen
ID: 7158350
Are you sure? emoreau, I thought "Execute" always returned a Recordset object reference if successful.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7158354
I am 110 % sure of this.

INSERT, UPDATE and DELETE statements can only return the number of affected records. To retreive this value, pass a long variable as the second parameter of the EXECUTE method.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7158417
sorry,CheChen,but emoreau is 1000% correct--- Only a SELECT query will return a recordset.

Arthur Wood
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 7158904
Well technically .Execute does ALWAYS return a recordset, however if it is NOT a select statement this is a Closed recordset object which is why the error message "Object is closed" is returned.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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