Sub CommandAndExec()
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
With conn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & "\mydb.mdb"
.Open
End With
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = conn
.CommandText = "Select * from Customers"
End With
Set rst = cmd.Execute
MsgBox rst.Fields(1).Value
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
End Sub
|