DoCmd.RunSQL method (Access)
The RunSQL method carries out the RunSQL action in Visual Basic.
Syntax
expression.RunSQL (SQLStatement, UseTransaction)
expression A variable that represents a DoCmd object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
SQLStatement | Required | Variant | 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. |
UseTransaction | Optional | Variant | 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. |
Remarks
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).
Example
The following example updates the Employees table, changing each sales manager's title to Regional Sales Manager.
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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기