Sub cmdConnect_Click()
' Declare the object variables
Dim cnStateUBookstore As Connection
Dim comPriceUpdate As Command
Dim rsStudents As Recordset
' Instantiate the variables
Set cnStateUBookstore = New Connection
Set comPriceUpdate = New Command
Set rsStudents = New Recordset
' Establish a connection
With cnStateUBookstore
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;" & _
"Data Source=MSERIES1;" & _
"Initial Catalog=StateUBookstore"
.Open
End With
' Create a Command object
With comPriceUpdate
.ActiveConnection = cnStateUBookstore
.CommandText = "SELECT StudentID FROM Students"
End With
' Build the recordset
Set rsStudents = comPriceUpdate.Execute
End Sub