Application.CloseCurrentDatabase (Access)
You can use the CloseCurrentDatabase method to close the current database, either a Microsoft Access database or an Access project (.adp) from another application that has opened a database through Automation.
For example, you might use this method from Microsoft Excel to close the database currently open in the Microsoft Access window before opening another database. The CloseCurrentDatabase method is useful when you have opened a Microsoft Access database from another application through Automation. After you have created an instance of Microsoft Access from another application, you must also create a new database or specify an existing database to open. This database opens in the Microsoft Access window. If you use the CloseCurrentDatabase method to close the database that is open in the current instance of Microsoft Access, you can then open a different database without having to create another instance of Microsoft Access.
' Enter the following in the Declarations section of the module.
Dim appAccess As Access.Application
Sub CreateForm()
Const strConPathToSamples = "C:\Program Files\Microsoft Office\Office12\Samples\"
Dim frm As Form, strDB As String
' Initialize string to database path.
strDB = strConPathToSamples & "Northwind.mdb"
' Create new instance of Microsoft Access.
Set appAccess = CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strDB
' Create new form.
Set frm = appAccess.CreateForm
' Save new form.
appAccess.DoCmd.Save , "NewForm1"
' Close currently open database.
appAccess.CloseCurrentDatabase
Set AppAccess = Nothing
End Sub