This sample project demonstrates how to create and execute a Command object using ADO 2.1.
Option Explicit
Private Sub Command1_Click()
Dim cnNWind As ADODB.Connection
Dim rsNWind As ADODB.Recordset
Dim cmNWind As ADODB.Command
'Instantiate the Command and Connection objects.
Set cnNWind = New Connection
Set cmNWind = New Command
'Open the connection using the Northwind DSN.
cnNWind.Open "northwind"
'Attach the connection to the Command object.
Set cmNWind.ActiveConnection = cnNWind
'Set command text and compile the command.
With cmNWind
.CommandText = "SELECT productname FROM products"
.Prepared = True
End With
'Execute the command and display the results.
Set rsNWind = cmNWind.Execute
Set Label1.DataSource = rsNWind
Label1.DataField = "ProductName"
'Clean up.
cnNWind.Close
Set cmNWind = Nothing
Set rsNWind = Nothing
Set cnNWind = Nothing
End Sub