我有一個使用Access 2007-2010的數據庫,我有一個AutoExec,自動啓動檢測何時以及如果用戶離開前端打開,它會在一小時後關閉。我使用了微軟網站https://msdn.microsoft.com/en-us/library/office/ff192885.aspx的檢測用戶空閒時間,並在結束時我保存並關閉了程序,而不是他們是如何做到的。我遇到的問題是它打破了用vba編寫的所有其他代碼。我有另一種形式的按鈕,它們複製表格中的所有東西,並改變用戶想要的內容,並且所有這些都可以工作,直到我添加了這個宏。當我將所有的代碼註釋掉以至於它什麼也不做,並且讓宏啓動時它仍然會破壞其他代碼。林不知道是否因爲我有宏啓動一個窗體與代碼來檢測空閒時間,不斷運行,導致其他部分工作。訪問DetectIdleTime AutoExec打破其他代碼
My Macro that is named "AutoExec"
這裏是我的檢測空閒時間
Option Compare Database
Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 60
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
Me.CurFormtxt = ActiveFormName
' 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
Me.TimeInactivitytxt = ExpiredMinutes
If ExpiredMinutes >= IDLEMINUTES Then
' ...if so, then reset the expired time to zero...
ExpiredTime = 0
' ...and close the program
Application.Quit acQuitSaveAll
End If
End Sub
什麼是隱藏窗體的TimerInterval設置?我必須說,我使用'Form_Timer'做了幾件事,它從來沒有破過任何東西。 – Andre
TimerInterval用於指定表單上定時器事件之間的時間間隔(以毫秒爲單位)。我從MS網站上得到了這個,只是改變了底部,關閉了數據庫,而不是他們所做的。你也可以發佈你的Form_Timer,我想看看它。 – Kayracer
對不起,我知道'TimerInterval'是什麼。 :)我的意思是:你的表單有哪些TimerInterval值?即您的子女多久召喚一次? – Andre