Execute

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.

Syntax
  SQL:
      EXECUTE procedure [param1[, param2[, …]]
  VBA:
      expression.Execute(Query, Options)

Key
   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'

Example

' 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)
dbs.Close 

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

Related:

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-2014
Some rights reserved