Solved

executing and adodb command

Posted on 2006-11-09
4
323 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
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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