If you want to get the number of records that were updated, inserted, or deleted by your query, you would read the RecordsAffected property on the object that executed your query after it had run.
So the above function was written to use another function, ExecuteSQL which takes an SQL string and an optional DAO database. Here is that function:
I wrote this so I could handle multiple SQL statements separated by semicolons. I am using an additional helper function called SplitSQLStatements to make sure I’m not splitting on semicolons inside of single quotes, but there are other situations where semicolons could be used (maybe in a SQL comment or if you are using parameters in your SQL statement maybe) Here is the SplitSQLStatements function:
Now let’s say you want to run a Passthrough Query against SQL Server and want to get the RecordsAffected. In that case you cannot use this method. You must use either a second query on the same connection to get the recordcount using special SQL Server syntax, or you need to create a stored procedure in SQL Server that will return the number of affected records. For more information on this see this article on StackOverflow: