文章編號: 210297 - 上次校閱: 2009年4月28日 - 版次: 4.0

如何在 Access 2000 偵測使用者閒置時間或非使用狀態

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

結論

本文將告訴您,如何建立程序,如果您的 Access 應用程式不會偵測任何使用者輸入指定的一段時間將會執行。它牽涉到建立隱藏的表單包含程式碼會持續閒置 (Idle) 時間的計數。

Microsoft 僅,為了說明提供程式設計範例,不提供任何明示或默示的保證。這包括,但不限於適售性或適合某特定用途之默示擔保責任。本文假設您已熟悉使用我們所示範的程式設計語言以及建立和偵錯程序所使用的工具。Microsoft 技術支援工程師可以協助解釋特定程序的功能,但它們不會修改這些範例以提供附加功能或建構程序,以符合您特定需求。

附註使用此程式碼來將記錄新增到表格中,當資料庫閒置時,可能會導致過度的記憶體耗用量。

如何建立 DetectIdleTime 表單

  1. 建立不以任何資料表或查詢為基準的空白表單,並命名 DetectIdleTime。
  2. 設定下列表單屬性:
       OnTimer: [Event Procedure]
       TimerInterval: 1000
    						
    注意:TimerInterval 設定指出頻率 (以毫秒為單位) 應用程式會檢查使用者閒置時間。如果設定為 1000年等於 1 秒。
  3. OnTimer 屬性設定為下列的事件程序:
    Sub Form_Timer()
       ' IDLEMINUTES determines how much idle time to wait for before
       ' running the IdleTimeDetected subroutine.
       Const IDLEMINUTES = 1
    
       Static PrevControlName As String
       Static PrevFormName As String
       Static ExpiredTime
    
       Dim ActiveFormName As String
       Dim ActiveControlName As String
       Dim ExpiredMinutes
    
       On Error Resume Next
    
       ' Get the active form and control name.
    
       ActiveFormName = Screen.ActiveForm.Name
       If Err Then
          ActiveFormName = "No Active Form"
          Err = 0
       End If
    
       ActiveControlName = Screen.ActiveControl.Name
          If Err Then
          ActiveControlName = "No Active Control"
          Err = 0
       End If
    
       ' Record the current active names and reset ExpiredTime if:
       '    1. They have not been recorded yet (code is running
       '       for the first time).
       '    2. The previous names are different than the current ones
       '       (the user has done something different during the timer
       '        interval).
       If (PrevControlName = "") Or (PrevFormName = "") _
         Or (ActiveFormName <> PrevFormName) _
         Or (ActiveControlName <> PrevControlName) Then
          PrevControlName = ActiveControlName
          PrevFormName = ActiveFormName
          ExpiredTime = 0
       Else
          ' ...otherwise the user was idle during the time interval, so
          ' increment the total expired time.
          ExpiredTime = ExpiredTime + Me.TimerInterval
       End If
    
       ' Does the total expired time exceed the IDLEMINUTES?
       ExpiredMinutes = (ExpiredTime / 1000) / 60
       If ExpiredMinutes >= IDLEMINUTES Then
          ' ...if so, then reset the expired time to zero...
          ExpiredTime = 0
          ' ...and call the IdleTimeDetected subroutine.
          IdleTimeDetected ExpiredMinutes
       End If
    End Sub
    
    
    					
  4. 在表單模組中建立下列的程序:
    Sub IdleTimeDetected (ExpiredMinutes)
       Dim Msg As String
       Msg = "No user activity detected in the last "
       Msg = Msg & ExpiredMinutes & " minute(s)!"
       MsgBox Msg, 48
    End Sub
    
    					

如何使用 DetectIdleTime 表單

若要隱藏 DetectIdleTime 表單應用程式開啟時,建立下列的自動執行巨集:
   Macro Name   Action
   ----------------------------
   AutoExec     OpenForm


   AutoExec Action Arguments
   ----------------------------
   OpenForm
   Form Name: DetectIdleTime
   View: Form
   Filter Name:
   Where Condition:
   Data Mode: Edit
   Window Mode: Hidden
				
您可以將程式碼加入至 IdleTimeDetected 程序中,所以如果沒有任何使用者活動 IDLEMINUTES 常值中所指定的時間的長度,程序執行。比方說,您可以讓 Access 下列事件程序而結束:
Sub IdleTimeDetected (ExpiredMinutes)
   Application.Quit acSaveYes
End Sub
				
此程序會使 Access 結束應用程式不須顯示對話方塊,儲存所有的物件。




?考

如需有關 Timer 事件中 Visual Basic 編輯器] 中,按一下 [說明] 功能表上的 [Microsoft Visual Basic 說明],並在 「 Office 小幫手 」 或 「 解答精靈 」 中輸入 Timer 事件 然後按一下 [搜尋] 以檢視主題。













這篇文章中的資訊適用於:
  • Microsoft Access 2000 Standard Edition
關鍵字:?
kbmt kbhowto kbhowtomaster kbprogramming KB210297 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:210297? (http://support.microsoft.com/kb/210297/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。