AFter 5 minute of no activity , hit close button automatically

aman

Registered User.
Local time
Today, 15:41
Joined
Oct 16, 2008
Messages
1,251
Hi All

I have to write a code in a form so that if nobody is doing any activity for 5 minutes then after 5 minutes automatically press Close button named BtnClose in that form.

Can anyone please help me in the code?

Regards
Aman
 
This is quite a common requirement. It is usually done by having a hidden form and utilising the timer event of the form. You should be able to find relevant posts in this forum...

Amendment... I thought you meant closing the db... But I think you could use the same code..
 
One main question is, how do you determine inactivity? Is it a lack of a mouse move, a click, a dropdown, a keypress or other combination that will determine whether a form is being used?

The other question is, does inactivity mean when the form has not been used for the last 5 minutes, or when the db has been inactive, or when the PC has been inactive?
 
Hi All

I have to write a code in a form so that if nobody is doing any activity for 5 minutes then after 5 minutes automatically press Close button named BtnClose in that form.

Can anyone please help me in the code?

Regards
Aman

You may use the following to set up the timer event in your form:
https://support2.microsoft.com/default.aspx?scid=kb;en-us;210297

Follow steps 1 - 3


Then you create the following subroutine (step 4) in your Form module

Code:
Private Sub IdleTimeDetected (ExpiredMinutes)
  If ExpiredMinutes > 4 Then 
     [COLOR=green]'cancel unfinished [/COLOR][COLOR=green]edit [/COLOR]
      If Me.Dirty Then Me.Undo    
      BtnClose_Click 
  End If
End Sub

Best,
Jiri
 
VbaInet, Inactivity means no mouse move or key press for five minutes and if Db has been inactive for 5 minutes then run the code.
 
You can't do exactly that but what you CAN do is set up a timer and have it do countdowns at some rate, say, every 10 seconds. Then set a function call in the mouse move and key press events to reset the timer countdown. If the countdown ever reaches 0 then you have your closure condition.

The "DB has been inactive for 5 minutes" seems tougher unless you NEVER have an action query or any VBA code (perhaps loop-based) that takes 5 minutes.

If you have loops or things that can take 5 minutes then your initial request is misguided and the timing should be reconsidered. If you never have such loops or actions then ignore that part of the question because any mouse/key action potentially will trigger something (eventually) that would cause DB activity anyway.
 

Users who are viewing this thread

Back
Top Bottom