Runing Access Queries
My favorite method for executing SQL, be it saved queries or raw SQL, is the Execute method of the Database object. You can execute a statement with a single line, like this:
<br /> CurrentDb.Execute “UPDATE titles SET price = price * 1.10″<br />
In this case, CurrentDB references the currently open database. Alternatively, you can create and load a Database object variable, which will allow you to accomplish more with this method. After setting the variable, you can execute a query, supply additional options and even read the number of rows affected. While this takes a few more lines, it is by no means verbose:
<br /> Dim dbs As DAO.Database, sql as String, iCount as Integer<br /> Set dbs = CurrentDb<br /> sql = “DELETE * FROM stores WHERE state=’WY’”<br /> ‘(not that there’s anything wrong with Wyoming!)<br /> dbs.Execute sql, dbFailOnError<br /> iCount = dbs.RecordsAffected <br />