Article ID: 164455
Article Last Modified on 1/19/2007
Sub CloseAccess()
Dim objAccess As Object
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = True
Msgbox "Microsoft Access is open; this procedure will now close it."
objAccess.Quit
Set objAccess = Nothing
End Sub
When you create Recordset or QueryDef objects in code, explicitly close
the object when you are finished with it. Microsoft Access automatically closes
those types of objects under most circumstances; however, if you explicitly
close the object in your code, you can avoid occasional instances when the
object remains open. The following sample code opens and closes a Recordset and
a QueryDef object in the Northwind sample database:
Sub CloseObjects()
Dim db As Database
Dim rs As Recordset
Dim qd As QueryDef
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenTable)
Set qd = db.QueryDefs("Invoices")
rs.MoveLast
MsgBox "The Employees recordset is open." & vbcr & _
"The last Employee ID is " & rs![EmployeeID] & "."
Msgbox "The Invoices query definition is open." & vbcr & _
"The first field in the query is " & qd.Fields(0).Name
' Explicitly close the Recordset and QueryDef objects.
rs.Close
qd.Close
End Sub
Dim objAccess As Object
Sub LeaveOpen()
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = True
End Sub
LeaveOpen
190074 ACC97: Unable to Quit Microsoft Access
147816 ACC: Using Microsoft Access as an Automation Server
145707 ACC: Using Automation to Print Microsoft Access Reports
Additional query words: can't cannot can not close down quit stop exit OLE quiting
Keywords: kbprb kbprogramming kbusage KB164455