ActiveConnection Property (ADO Command Object)

Home | About me | EXCEL VB Programming (XL97-2003) | ACCESS Programming | EXCEL VB.Net Programming | EXCEL Spreadsheet Functions Material Management  |  Guestbook
 

ADO Command Object >>ActiveConnection Property

The ActiveConnection property sets or returns a variant value defining the Connection object to which the Command object belongs, or returns a string value if there is no connection.

The ActiveConnection property is used to indicate the specific Connection object with which the Command object is to be associated and will use for execution. If the connection is closed, this property sets or returns a string that contains the definitions for the connection. If the connection is open, this property sets or returns a variant that is the Connection object to which the Command object is currently assigned. The default is a null object reference.
 
If you Set this property to a closed Connection object, an error will be generated. An error will also occur if you try to call the Execute method of the Command object before the connection is open.
 
If you close the Connection that is associated with a Command object, the ActiveConnection property will be set to Nothing.
 
If you set this property to Nothing, the Command object is disassociated from the Connection object. Note that both the Command and Connection objects will continue to exist. As long as both objects exist, you can use the ActiveConnection property to reset the same association, or set a new association between the Command object and another Connection object.

Syntax

objcommand.ActiveConnection

Example

Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open "D:\Mydata\Northwind.mdb"

Set comm = New ADODB.Command
comm.
ActiveConnection = conn
Debug.Print (comm.ActiveConnection)

Or use:

set comm.ActiveConnection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Mydata\Northwind.mdb"