DoCmd.RunSQL (Access)

The RunSQL method carries out the RunSQL action in Visual Basic.

You can use the RunSQL action to run a Microsoft Access action query by using the corresponding SQL statement. You can also run a data-definition query. This method only applies to Access databases. The maximum length of the SQLStatement argument is 32,768 characters (unlike the SQLStatement action argument in the Macro window, whose maximum length is 256 characters).

RunSQL (SQLStatement, UseTransaction)


Public Sub DoSQL() 
 
    Dim SQL As String 
     
    SQL = "UPDATE Employees" & _ 
          "SET Employees.Title = 'Regional Sales Manager'" & _ 
          "WHERE Employees.Title = 'Sales Manager'" 
 
    DoCmd.RunSQL SQL 
     
End Sub

Arguments

The following argument is required

SQLStatement (String) - A string expression that's 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.

Optional arguments

The following argument is optional

UseTransaction (Boolean) - Use True (1) to include this query in a transaction. Use False (0) if you don't want to use a transaction. If you leave this argument blank, the default (True) is assumed.