Solved

executing and adodb command

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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

15 Experts available now in Live!

Get 1:1 Help Now