Microsoft Office Tutorials and References
In Depth Information
When you run an update, append, make a table, or delete a query from within
a VBA procedure, use the query’s SQL statement as the argument to a
RunSQL statement in your code.
Before your procedure ends, you may want to close both the recordset and the
active connection to the local tables to prevent those objects from remaining
open after your code moves on to other tasks. To close a recordset, follow the
recordset’s name with a .Close method, as in the following example:
To terminate the connection to the local tables in the database and remove
the recordset and connection objects from the computer’s memory, set each
one to the keyword Nothing, as shown here:
Set myRecordset = Nothing
Set myConnection = Nothing
So that’s what SQL and recordsets are all about in VBA. Will there ever come
a time where you need to write all this complex code to perform some task?
It depends on how complex your database projects are. One thing is for
sure, though: If you ever inherit a database that someone else wrote, and
you come across a bunch of code with SQL statements and recordsets, the
information in this chapter will at least help you better understand what’s
going on with that code.