I use some data in Excel that is stored in an Access database. If the user wants to add / change data, this must be done in the Access frontend (in my case). In order to provide an easy way to do so I placed an 'edit data' button inside the Excel sheet to open Database + Form:
' standard module
Const mstrDatabase = ' path & filename
Const mstrForm = ' name of form to edit data
Private moAccessApp As Access.Application
' module level object to keep database open after button_click-code finished
Sub OpenDatabase_Button_Click()
Set moAccessApp = CreateObject("Access.Application")
moAccessApp.OpenCurrentDatabase mstrDatabase
moAccessApp.Visible = True
moAccessApp.DoCmd.OpenForm mstrForm
End Sub
If the user closes Access, the moAccessApp
object is still set (Debug.Print (moAccessApp Is Nothing)
prints out False
).
Questions:
- How can I determine if Access has been closed by user?
- Is it possible to fire an event in Excel in that case?
ad (1): I like to prevent opening a second instance in case of button clicked a second time
ad (2): I want to refresh data in Excel at least after close of database (although I know the user may change data in Access and switch over to Excel again without closing Access).