RunSQL Method

Applies To

DoCmd Object.

Description

The RunSQL method carries out the RunSQL action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.RunSQL sqlstatement

The RunSQL method uses the following arguments.

Argument

Description

sqlstatement

A string expression that is a valid SQL statement for an action query or a data-definition query. It uses an INSERT INTO, DELETE, SELECT...INTO, UPDATE, CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, or DROP INDEX statement. Include an IN clause if you want to access another database.


Remarks

The maximum length of the sqlstatement argument is 32,768 characters (unlike the SQL Statement action argument in the Macro window, whose maximum length is 256 characters).

See Also

DoCmd Object, OpenQuery Method, RunSQL Action.

Example

This example updates the Employees table, changing each sales manager’s title to Regional Sales Manager.


DoCmd.RunSQL "UPDATE Employees " & _
    "SET Employees.Title = 'Regional Sales Manager' " & _
    "WHERE Employees.Title = 'Sales Manager';"