OptionCompare Database
OptionExplicitSub subCloseObjects()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenTable)
Set qd = db.QueryDefs("Invoices")
rs.MoveLast 'Move to the last record in the Recordset.
MsgBox "The Employees Recordset is open." & vbCrLf & _
"The last Employee ID is " & rs![EmployeeID] & "."
MsgBox "The Invoices query definition is open." & vbCrLf & _
"The first field in the query is " & qd.Fields(0).Name
'Explicitly close the Recordset and QueryDef objects.
rs.Close
qd.Close
EndSub