Command.Execute method : ADODB Command « Access « VBA / Excel / Access / Word

Command.Execute method

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"
   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

   Set rst = Nothing
   Set conn = Nothing
End Sub


Related examples in the same category

1.Use ADODB.Command to create a view
2.Using a Command Object to query table