Alex & Access

December 12, 2010

DAO RecordsAffected property

Filed under: Access — access @ 7:15 am

RecordsAffected property returns the number of records affected by the most recently invoked Execute method. Can be useful when you need to update a record in a table, and if record not exists – add it. Normally this is solved by opening recordset and using NoMatch property to test if record exists. Using RecordsAffected property you can do this in 3 lines:

Dim dbs As DAO.Database
Set dbs = CurrentDb
dbs.Execute "UPDATE Sales SET Amount=Amount + " & _
varAmount & " Where SalesDate=" & varDate, dbFailOnError
If dbs.RecordsAffected = 0 Then
dbs.Execute "INSERT INTO Sales (Amount, SalesDate) Values(" _ & varAmount & ", " & varDate & ")", dbFailOnError
End If

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: