Hello,
I've created a dummy form that remains hidden while my front end app is open. I am attempting to execute a function during the Close event of this form which, it is my understanding, should take place when a user closes the app. However, it doesn't seem to work that way in all cases.
To be specific, I call a function that will remove a specific Access Reference (Excel). As you may have guessed, this is my attempt at version-proofing against Excel by calling a function from the AutoExec macro to add the Excel reference during start up which requires that no newer or missing/broken Excel reference already exist. Everyone using the app will have Excel, but not necessarily as new as 2007, which is what the development environment has.
Anyway, I can get this to work, but only if I close the database "properly" via command button or closing a Form that has "CloseCurrentDatabase" in its Close event. The next time I open the app, if I hold Shift to bypass AutoExec, I can check references and see that Excel is not marked. However, if I close the app via the red "X" for the Access windows itself, the removal of the excel reference doesn't seem to take.
I have confirmed that the function is successfully called and successfully executes by adding a simple MsgBox notification after the removal, but again, the removal doesn't "stick". Any idea what I might be missing here? Or is this just another undocumented "feature"?
Here's the relevant code:
No matter if I close the app by closing the form or by clicking the "X" for Access, I get the MsgBox that tells me that the reference was successfully removed. Furthermore, I've debugged it with a breakpoint and followed the code step by step and confirmed that it executes properly as well.
I've created a dummy form that remains hidden while my front end app is open. I am attempting to execute a function during the Close event of this form which, it is my understanding, should take place when a user closes the app. However, it doesn't seem to work that way in all cases.
To be specific, I call a function that will remove a specific Access Reference (Excel). As you may have guessed, this is my attempt at version-proofing against Excel by calling a function from the AutoExec macro to add the Excel reference during start up which requires that no newer or missing/broken Excel reference already exist. Everyone using the app will have Excel, but not necessarily as new as 2007, which is what the development environment has.
Anyway, I can get this to work, but only if I close the database "properly" via command button or closing a Form that has "CloseCurrentDatabase" in its Close event. The next time I open the app, if I hold Shift to bypass AutoExec, I can check references and see that Excel is not marked. However, if I close the app via the red "X" for the Access windows itself, the removal of the excel reference doesn't seem to take.
I have confirmed that the function is successfully called and successfully executes by adding a simple MsgBox notification after the removal, but again, the removal doesn't "stick". Any idea what I might be missing here? Or is this just another undocumented "feature"?
Here's the relevant code:
Code:
Private Sub Form_Close()
If fRemoveExcel = True Then
MsgBox "Excel Removed."
CloseCurrentDatabase
Else: End If
End Sub
Code:
Public Function fRemoveExcel() As Boolean
Dim ref As Access.Reference
Dim iCount As Integer
Dim i As Integer
'# Find Excel reference and remove it
iCount = Application.References.Count
For i = 1 To iCount
Set ref = Access.References(i)
If ref.Name = "Excel" Then
Access.References.Remove ref
fRemoveExcel = True
Else
fRemoveExcel = False
End If
Next
Set ref = Nothing
End Function
Last edited: