Microsoft 提供的编程示例仅用于进行说明,而不提供明示或默示担保。 这包括但不限于适销性或对特定用途的适用性的默示担保。 本文假设您熟悉正在演示的编程语言和用于创建和调试过程的工具。 Microsoft 支持工程师可以帮助解释特定过程的功能,但他们不会修改这些示例以提供新增功能或构建步骤以满足你的特定需要。
在 Microsoft Office Access 2003 或早期版本的 Access 中,在 frmAppShutDown 窗体的设计视图中,单击“视图”菜单上的“代码”。 在 Microsoft Office Access 2007 中,在 frmAppShutDown 窗体的设计视图中,单击“设计”选项卡,然后单击“工具”组中的“查看代码”。 键入或粘贴以下代码:
VB
OptionExplicitDim boolCountDown AsBooleanDim intCountDownMinutes AsIntegerPrivateSub Form_Open(Cancel AsInteger)
' Set Count Down variable to false' on the initial opening of the form.
boolCountDown = FalseEndSubPrivateSub Form_Timer()
OnErrorGoTo Err_Form_Timer
Dim strFileName AsString
strFileName = Dir("c:\MyData\chkfile.ozx")
If boolCountDown = FalseThen' Do nothing unless the check file is missing.If strFileName <> "chkfile.ozx"Then' The check file is not found so ' set the count down variable to true and' number of minutes until this session' of Access will be shut down.
boolCountDown = True
intCountDownMinutes = 2EndIfElse' Count down variable is true so warn' the user that the application will be shut down' in X number of minutes. The number of minutes' will be 1 less than the initial value of the' intCountDownMinutes variable because the form timer' event is set to fire every 60 seconds
intCountDownMinutes = intCountDownMinutes - 1
DoCmd.OpenForm "frmAppShutDownWarn"
Forms!frmAppShutDownWarn!txtWarning = "This application will be shut down in approximately " & intCountDownMinutes & " minute(s). Please save all work."If intCountDownMinutes < 1Then' Shut down Access if the countdown is zero,' saving all work by default.
Application.Quit acQuitSaveAll
EndIfEndIf
Exit_Form_Timer:
ExitSub
Err_Form_Timer:
ResumeNextEndSub