
ADO Command Object Error 3711 Invalid Operation
Quote:
>Hi:
>I'm new to ADO. With VB and Access,I am trying to Select records from
>a table using
>RecordsetObject.open ("Select * from ....")and later INSERT the
>recorset values into a another table. I am using a Command object to
>INSERT.
>I set the command Text,type,activeconnection etc.
>I get a runtime error'3711' at the INSERT statment.
>says "Invalid Operation on Object While processing another command"
>Why is this?This occurs only when i run the program using f5...during
>step by step exec( F8) it runs without errors.
>I have used the same ADO conn for both the Recorset and Command
>Objects.Is this right? Should I release any object to Close or nothing?
No - you should be able to use a single connection for everything.
Quote:
>Also This error occurs for the second record in the loop for Inserting.
>The first record gets INSERTED well.
I am getting the impression you are changing the commandtext? Hmm..
Anyway, this is how I would do something like this:
comm.activeconnection = conn
comm.commandtype=1
comm.commandtext = "insert into tableB(field1,field2,field3) " & _
"values (?,?,?)"
comm.prepared=true
rs.open "select field1,field2,field3 from tableA", conn, _
adOpenStatic, adLockReadOnly
do while not rs.eof
cmd.execute iNum,array(rs.fields(0).value,rs.fields(1).value, _
rs.fields(2).value)
rs.movenext
loop
rs.close
HTH,
Dan Bush
Battle Ground.wa.us
Please No Spam, to email, change .com to .net