In SQL the Execute command invokes the execution of a procedure. In VBA the Execute method runs an action query or executes an SQL statement.

      EXECUTE procedure [param1[, param2[, …]]
      expression.Execute(Query, Options)

   procedure         The name of the procedure to be executed.

   param1, param2,   Values for the parameters defined by the procedure.

   query             The SQL query to run

   Options           How to run the query:
                     dbDenyWrite, dbInconsistent, dbConsistent,
                     dbSQLPassThrough, dbFailOnError, dbSeeChanges,
                     dbRunAsync, dbExecDirect

When running against a linked SQL server table specify the option dbSeeChanges, this will avoid the error: 'You must use the dbSeeChanges option with OpenRecordsetwhen accessing a SQL server table that has an IDENTITY column'


' In VBA
'Open a database
Set dbs = OpenDatabase("C:\demo\Northwind.mdb")
' Delete employee records where title is Trainee.
dbs.Execute ("DELETE * FROM Employees WHERE Title = 'Trainee';" , dbFailOnError Or dbSeeChanges)

“Never was anything great achieved without danger” ~ Niccolo Machiavelli


Delete - Delete records.
Insert - Add records to a table (append query).
Select - Retrieve data from one or more tables or queries.
Update - Update existing field values in a table.

© Copyright SS64.com 1999-2016
Some rights reserved