Team LiB
Previous Section Next Section

RunSQL

Runs a SQL statement.

Syntax

DoCmd.RunSQL SQLStatement[, UseTransaction]

with the following parameters:

SQLStatement

A SQL statement for an action query or a data definition query.

UseTransaction

A Boolean that indicates whether the query is included in a transaction. Its default value is True.

Example

The following UPDATE query replaces the substring “Street” in the txtAddress field of the tblCustomer table with the substring “St.”:

Public Sub RunStreetUpdate()

Dim strSQL As String

' Make backup copy of tblCustomer
DoCmd.CopyObject , "tblCustomer Backup", acTable, "tblCustomer"
         
' Change "Street" to "St."
strSQL = "UPDATE tblCustomer " & _
         "SET tblCustomer.txtAddress = 
Replace([tblcustomer].[txtAddress],'Street','St.') " & _
         "WHERE ((InStr([tblcustomer].[txtaddress],'Street')>0));"

DoCmd.RunSQL strSQL

End Sub

Comments


Team LiB
Previous Section Next Section