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

I have the following code, I'm trying to:
1) connect to a database
2) Create a command object so that I can then use the command object for
querying.

My code is below, I keep getting an Object Variable or With block not set
for this line: Set theCommand.ActiveConnection = theConnection.

Dim theConnection As ADODB.Connection
Dim connectionString As String
Sub ConnectToDatabase()
'Dim theConnection As ADODB.Connection
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Mydb.mdb"

Set theConnection = CreateObject("ADODB.Connection")
theConnection.Open (connectionString)
Call GetRevenueFigure
End Sub

Sub GetRevenueFigure()
Dim sqlStr As String
Dim theCommand As ADODB.Command
sqlStr = "SELECT * FROM Revenue;"

Set theCommand.ActiveConnection = theConnection
theCommandText = sqlStr

End Sub


This is the first time I've used ADO so bear with me if I'm way off the mark.
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default ADO Connections

you need

SET theCommand = NEW Command



"Simon" wrote:

I have the following code, I'm trying to:
1) connect to a database
2) Create a command object so that I can then use the command object for
querying.

My code is below, I keep getting an Object Variable or With block not set
for this line: Set theCommand.ActiveConnection = theConnection.

Dim theConnection As ADODB.Connection
Dim connectionString As String
Sub ConnectToDatabase()
'Dim theConnection As ADODB.Connection
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Mydb.mdb"

Set theConnection = CreateObject("ADODB.Connection")
theConnection.Open (connectionString)
Call GetRevenueFigure
End Sub

Sub GetRevenueFigure()
Dim sqlStr As String
Dim theCommand As ADODB.Command
sqlStr = "SELECT * FROM Revenue;"

Set theCommand.ActiveConnection = theConnection
theCommandText = sqlStr

End Sub


This is the first time I've used ADO so bear with me if I'm way off the mark.
Thanks.

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
Connections bug? Kevin Parkin Excel Programming 1 January 31st 07 02:06 AM
remote connections John A Grandy New Users to Excel 1 May 26th 06 12:58 AM
ADODB Connections MChrist Excel Programming 1 December 7th 05 08:43 PM
DSN-Less Connections Sauron[_17_] Excel Programming 9 June 21st 04 12:04 PM
Deleting old connections Janene[_2_] Excel Programming 0 June 9th 04 01:06 AM


All times are GMT +1. The time now is 02:52 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"