Reputation: 1
I have a front end database that is refreshed every morning by a BOT PC. All of our databases are refreshed this way with continuous success, except this one. It fails to refresh quite often stating that the "Database is in use". But when I view the "laccdb' file, it easily deleted. Which leads me to believe one or more users is leaving the database open when they logoff for the day. However at roughly 2 am cst, our network forces all open applications to close, sometimes resulting in what we call "hung sessions", an application that appears to be open but is truly not.
Of course everyone says they close it properly. So.... is there a way that Access vba can identify if the close event was initiated by a user or by the system? And/or is there a way to identify the user initiated close method such as clicking the "Big X" or entering Alt-F4 ?
I have added a "Exit Application" command button, of course that only works when they click the button. The vba OnClose Event works no matter how it is closed, by the WindowsLogon its reporting is the logon of the user, no the close method.
Upvotes: 0
Views: 58
Reputation: 31
if I understand the problem correctly, you wish to determine whether an Access application was terminated by a user action (a button click in this case) or not. This is fairly trivial to implement with a module-level flag variable that is set only when the action (button click) occurs and tested wherever needed. For example, in the form that has the exit button's code module:
Option Compare Database
Option Explicit
Private boolUserExit As Boolean ' Flag indicating whether the exit button was clicked.
Private Sub cmdExit_Click()
boolUserExit = True ' Set the flag to indicate the exit button was clicked.
' Do your shutdown procedure.
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not boolUserExit Then ' The flag will only be set if the exit button was first clicked.
' Handle non-user shutdowns here.
End If
boolUserExit = False ' Always reset the flag after use.
End Sub
Upvotes: 0