Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ADO recordset error

Hi,

I get the following error when trying to run a VBA code from excel.
----------- Error Start -----------
Run-time error '3704':
Operation is not allowed when the object is closed.
----------- Error End -----------


I'll put the code here and explain a bit more after that.
----------- Code Start -----------
Public Sub UpdateTable1()

Dim objConn As New ADODB.Connection
Dim objCmd As New ADODB.Command
Dim objRs As New ADODB.Recordset

With Worksheets("Compare")
objCmd.CommandText = "USE " & ComboBox1.Text & _
" select name from dbo.sysobjects " & _
"where OBJECTPROPERTY(id, N'IsUserTable') = 1 " & _
"and name < 'dtproperties'"
objCmd.CommandType = adCmdText

Set objConn = GetNewConnection
objCmd.ActiveConnection = objConn

Set objRs = objCmd.Execute

Do While Not objRs.EOF
ComboBox3.AddItem (objRs(0))
objRs.MoveNext
Loop
End With

End Sub
----------- Code End -----------


That code works if I use some simpler query.
I've checked with SQL Profiler and the query comes to the
SQL Server as it should be. I've ran the query in Query Analyzer
and it works there.

I would really appreciate any help on this.

----
mkarja
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default ADO recordset error

mkarja wrote:
Operation is not allowed when the object is closed.


The query does not return a row set. Try connecting to the database,
rather than the server, by specifying the initial catalog in the
connection string, then omitting the USE <database from the SQL text.

Jamie.

--

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ADO recordset error

That worked. Thank you very much.

I'm just curious why it didn't work with that query but worked with
a simple select query. Even when there was that USE <database in the
beginning.

----
mkarja


"Jamie Collins" wrote in message roups.com...
mkarja wrote:
Operation is not allowed when the object is closed.


The query does not return a row set. Try connecting to the database,
rather than the server, by specifying the initial catalog in the
connection string, then omitting the USE <database from the SQL text.

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 97 ADODB Recordset.Find "Invalid Use" error Robin Hammond[_2_] Excel Programming 1 August 27th 04 12:47 PM
ADO recordset returns -1 Dennis Excel Programming 4 August 16th 04 09:52 AM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM
ADODB Recordset Seth[_3_] Excel Programming 0 August 5th 03 02:15 PM


All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"