Idle Time Utility Not Working in Access 2007 (1 Viewer)

khwaja

Registered User.
Local time
Tomorrow, 04:27
Joined
Jun 13, 2003
Messages
254
I have a 2003 database front end that I publish in 2007 as well. I always have had a small utility in my DB that helped me to automatically close the front end after certain period of inactivity (for maintenance) and it worked well. For some reason this is not working in the Access 2007 mde file. I wonder if if something has changed in A2007 or whether I am making a mistake in the code. My process is as under:

I run an autoexec command which opens an invisible form
This form has the following code:

Private Sub Form_Timer()

' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 20

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) / 55
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



Sub IdleTimeDetected(ExpiredMinutes)

'Dim Msg As String
'Msg = "No user activity detected in the last "
'Msg = Msg & ExpiredMinutes & " minute(s)!"
'MsgBox Msg, 48
Application.Quit A_SAVE
End Sub

I have tested it in A2003 and it works. Will appreciate if I could get some guidance.
 

JHB

Have been here a while
Local time
Today, 20:27
Joined
Jun 17, 2012
Messages
7,732
The marked parameter isn't correct.
Code:
Application.Quit [B][COLOR=Red]A_SAVE[/COLOR][/B]
Correct parameters are
Code:
acQuitSaveNone
acQuitSaveAll
acQuitSaveNone
I would suggest you to comment out the error handler until your code runs okay.
Why do you've two blocks of the same code just after each other?
Code:
' 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
 

vbaInet

AWF VIP
Local time
Today, 19:27
Joined
Jan 22, 2010
Messages
26,374
Please use code tags when you post code on the forum:

http://www.access-programmers.co.uk/forums/showthread.php?t=200247

If you do your code becomes readable and you'll get more responses.

As for the A_SAVE variable, I think that's a global constant that khwaja has defined but still worth pointing out.

Now when you say "it's not working", what exactly do you mean?
* Does it throw an error?
* Does nothing happen at all? Are you sure the code is even running?
Being Access 2007 code is initially disabled so perhaps you need to add your db to a Trusted Location and permit macros/code to run.
 

Users who are viewing this thread

Top Bottom