A Connection object provides you with a connection to the data that the Command
object will operate on and the Recordset will retrieve. If you plan to connect your Recordset
to data outside of your application, you must have at least one Connection object in the application.
The minimum steps you need to take to have a functional Connection object
are as follows:
STEP BY STEP
8.7 Establishing a Connection Object
-
Make sure that you have set a reference to the ADO Library, as discussed in
Chapter 8, under the section "Programming
with ADO."
-
Declare an object variable whose type is ADODB.Connection. If you want to program
the event procedure of the object, use the WithEvents keyword.
-
Set the Connection object's ConnectString property to reflect a valid OLE DB
provider, or specify the provider string in the next step, as follows:
cnNWind.ConnectString = "Provider=Microsoft.Jet.OLEDB.3.51;"
-
Call the Connection object's Open method. If you didn't specify the ConnectString
property in the preceding step, you need to pass the connection string as the
first argument to the Open method, as in the following example :
cnNWind.Open "Provider=Microsoft.Jet.OLEDB.3.51;"
& _
"Data Source= C:\DataSamples\Nwind.mdb"