Code not working in MDE - pulling hair out!

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.

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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
No idea why but changing the detectidletime code to the below worked.


Code:
Sub IdleTimeDetected()
    On Error Resume Next
    With Screen.ActiveForm
        If .Dirty = True Then .Undo
    End With
    On Error GoTo 0
    Application.Quit acQuitSaveAll
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,156
Messages
6,129,192
Members
449,492
Latest member
steveg127

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top