다음을 통해 공유


DoCmd.RunSQL Method (Access)

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

Syntax

.RunSQL(SQLStatement, UseTransaction)

A variable that represents a DoCmd object.

Parameters

Name

Required/Optional

Data Type

Description

SQLStatement

필수

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

선택

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

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 Microsoft Access databases.

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).

Links provided by:커뮤니티 구성원 아이콘 The UtterAccess community | About the Contributors

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

About the Contributors

UtterAccess(영문일 수 있음)는 Microsoft Access 위키 및 도움말 포럼입니다. 가입하려면 여기를 클릭하십시오(영문일 수 있음).

참고 항목

개념

DoCmd Object Members

DoCmd Object