Solved

ADO Execute command

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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