admin管理员组文章数量:1305926
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.
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.
Share Improve this question asked Feb 3 at 14:09 Elena PeralesElena Perales 1 4- 2 If you open the .laccdb file in notepad you will be able to see the Machine Name of the last people to open the database. The lockfile is being left behind by the forced close - You could get your Bot PC to delete the .laccdb file before the refresh – CHill60 Commented Feb 3 at 14:44
- You could refresh the local frontend at launch. This is a proven and very fast method described in detail in my article: Deploy and update a Microsoft Access application in a Citrix environment – Gustav Commented Feb 3 at 15:21
- I would like to create an log of user open and close, and the close method utilized to close the database... including whether the user initiated the close or if the system initiated the close. In the long run, this could be something we use to troubleshoot issues with other databases and to determine if users are following protocol. – Elena Perales Commented Feb 3 at 18:19
- I have Users table. Code updates user record with computername (in case user at different workstation, which is rare) when database opens and Exit button removes computername. I don't care about history, just which computer has the db "hung". I also customize db to disable X close from forms and app and cannot close via ribbon. You already know what you want to do so go for it and when you have code with issue, post question. – June7 Commented Feb 3 at 18:38
1 Answer
Reset to default 0if 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
本文标签:
版权声明:本文标题:MS Access vba to determine if the database close action was initiated by the user or by the systemnetwork? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741816118a2399088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论