>

RecordsAffected Property

Applies To

Database Object, QueryDef Object.

Description

Returns the number of records affected by the most recently invoked Execute method.

Return Values

The return value is an integer from 0 to the number of records affected by the most recently invoked Execute method on either a Database or QueryDef object. The data type is Long.

Remarks

The RecordsAffected property contains the number of records deleted, updated, or inserted when running an action query. When you use the Execute method to run a QueryDef object, the RecordsAffected property setting is the number of records affected.

Note

The RecordsAffected property setting is the same as the value returned by the ExecuteSQL method.

Example

This example prints the number of records updated by an action query.


Dim dbsBiblio As Database, lngResults As Long
Set dbsBiblio =  DBEngine.Workspaces(0).OpenDatabase("Biblio.mdb")
dbsBiblio.Execute "Update Titles Set [Year Published] = 1994 " _
& " WHERE Title = 'To Kill an SQL Query' " lngResults = dbsBiblio.RecordsAffected Debug.Print lngResults & " records were changed." dbsBiblio.Close
Example (Microsoft Access)

The following example prints the number of records updated by an action query.


Sub RecordsUpdated()
    Dim dbs As Database, qdf As QueryDef
    Dim strSQL As String
    
    ' Return Database variable that points 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 object. qdf.Execute Debug.Print qdf.RecordsAffected End Sub