Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

If you’ve ever wondered whether a SQL statement you executed actually modified any records, there is a property of the DAO database object that can help you.

You can get the number of affected records of a DELETE, UPDATE, or INSERT type query immediately after you’ve run it. Use this syntax:

Dim myDb as DAO.Database
Set myDb = CurrentDb

myDb.Execute "DELETE * FROM tmpCustomers"

Debug.Print myDb.AffectedRecords

myDb.Execute "INSERT INTO tmpCustomers VALUES ( 15, 'Bob', 'Smith')"

Debug.Print myDb.AffectedRecords

myDb.Execute "UPDATE tmpCustomers SET FirstName='Robert' WHERE FirstName='Bob'"

Debug.Print myDb.AffectedRecords
Visual Basic

This also works if you are using a recordset that is based on the DAO.Database typed object. It will update the value with each query, so you need to make sure you use the property before you do any additional queries.

Sign up For a Daily Email Adventure in Microsoft Access

Every business day (typically M-F), I'll send you an email with information about my ongoing journey as an advanced Access application developer. It will be loaded with my tips and musings.

    We won't send you spam. Unsubscribe at any time.