Solved

executing and adodb command

Posted on 2006-11-09
4
333 Views
Last Modified: 2012-05-05
I have the following connect string constant:
Global Const scnn_ado_mcneil = "DSN=jjtpsqlmcneil;Server=pauljmcneil;Database=jjtptab13SQL;Trusted_Connection = Yes;"

I have the following code to use an adodb command to update a table
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command

Set cnn = New ADODB.Connection
cnn.ConnectionString = scnn_ado_mcneil
cnn.Open
ssql = "UPDATE dbo.tblWant SET Bought=0 WHERE CustomerID=1"
Set cmd = New ADODB.Command
cmd.CommandText = ssql
cmd.Execute
 
On the line cmd.Execute I get the error:
"The connection cannot be used to perform this operation. It is either closed or invlaid in this context.
0
Comment
Question by:paulmcneil
[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
  • 3
4 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17907371
Any reason u are using a ADO command to do it?

Wont

cnn.Execute ssql

do? i.e use ADODB.Connection execute method
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17907379
If u use the Command object, u need to give it a connection

e.,g.

cmd.ActiveConnection = cnn
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17907389
Of course, if u dont want to use ADO, there is the simple way of

DoCmd.RunSQL ssql

or even perhaps

CurrentDB.Execute ssql
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17907555
Well - those will work in a linked table set up - but the SQL will need altering (i.e. "dbo." :-)

Oh - and don't forget when setting the connection...

Set  cmd.ActiveConnection = cnn
'^^
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

738 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