PC Review


Reply
Thread Tools Rate Thread

ADO Connections

 
 
Simon
Guest
Posts: n/a
 
      26th Nov 2008
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 With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Nov 2008
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lingering Idle Oracle Connections? Persistent connections? jobs Microsoft ASP .NET 2 16th Nov 2007 03:37 AM
PPPOE connections created show up as Dial-up connections =?Utf-8?B?amFja2ll?= Windows Vista Networking 0 6th Oct 2007 07:20 AM
Inbound connections fail, outbound connections are fine - firewall shut off, very strange wwworldwideweb@gmail.com Windows XP General 0 18th Aug 2007 05:28 PM
Disappearing Dial-up connections in the network connections folder Effegy Windows XP Networking 0 9th Jun 2004 08:45 PM
>My Network Connections window does not have anything called Incoming Connections lhd_5113 Windows XP Networking 1 26th Nov 2003 08:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:27 AM.