Solved

ADO Execute command

Posted on 2002-07-16
5
178 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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
Are you sure? emoreau, I thought "Execute" always returned a Recordset object reference if successful.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now