Execute Method Example (MDB)

The following example executes an action query and prints the number of records affected:

Sub RecordsUpdated()
    Dim dbs As Database, qdf As QueryDef
    Dim strSQL As String
    
    ' Return reference to current database.
    Set dbs = CurrentDb
    strSQL = "UPDATE Employees SET Title = " _
        & "'Senior Sales Representative' " _
        & "WHERE Title = 'Sales Representative';"
    ' Create new QueryDef.
    Set qdf = dbs.CreateQueryDef("UpdateTitles", strSQL)
    ' Execute QueryDef.
    qdf.Execute
    Debug.Print qdf.RecordsAffected
    Set dbs = Nothing
End Sub