BrianMH
Well-known Member
- Joined
- Mar 26, 2008
- Messages
- 1,490
I've got the following code on a hidden form in my access database to close the database after a certain amount of idle time. I added some code to troubleshoot it to update the status bar with the idle time and if the condition that should call the closing macro is true. It works as expected when run from an MDB but when I convert it to MDE it isn't shutting once true. I know it's running because the status bar does update but even when the condition is true it is not closing.
This is the code it calls. It is in a separate module than the form. Again it works fine in the MDB but not the MDE.
Code:
Private Sub Form_Timer()
If dtmIdle = 0 Then dtmIdle = Now()
Call CloseRequest
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
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
If (PrevControlName = "") Or (PrevFormName = "") _
Or (ActiveFormName <> PrevFormName) _
Or (ActiveControlName <> PrevControlName) Then
PrevControlName = ActiveControlName
PrevFormName = ActiveFormName
dtmIdle = Now()
End If
ExpiredMinutes = (Now() - dtmIdle) * 1440
Dim RetVal As Variant
Dim sStatus As String
Dim sTest As String
If ExpiredMinutes >= IDLEMINUTES Then sTest = "true" Else: sTest = "false"
sStatus = CStr(ExpiredMinutes) & " - " & sTest
RetVal = Application.SysCmd(4, sStatus)
If ExpiredMinutes >= IDLEMINUTES Then
ExpiredTime = 0
IdleTimeDetected ExpiredMinutes
End If
End Sub
This is the code it calls. It is in a separate module than the form. Again it works fine in the MDB but not the MDE.
Code:
Sub IdleTimeDetected(ExpiredMinutes)
Dim frmActive As Form
On Error Resume Next
Set frmActive = Screen.ActiveForm
On Error GoTo 0
If Not frmActive Is Nothing Then
With Screen.ActiveForm
If Screen.ActiveForm.Dirty = True Then
.Undo
End If
End With
End If
Application.Quit
End Sub