Solved

Detect idle time and close a form automatically

Posted on 2003-10-23
5
500 Views
Last Modified: 2012-06-27
Hi

How do I detect if an open form has not had any activity (keystrokes) for say 2 minutes then automatically close the form?

0
Comment
Question by:andrewreilly
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 50 total points
Comment Utility
Paste following in a standard module, under module tab:

Public TimeVarForm1 As Date

Public Function fnResetTime1()
   TimeVarForm1 =Now()
End Function
------------
In Design view of your Form1, select form and in it time interval enter 10000 to check it every 10 seconds.

In Timer event of Form1 include:

Private Sub Form_Timer()
If (Now() - TimeVarForm1) * 24 * 60 * 2 * 60 > 120 Then
DoCmd.Close acForm, "Form1", acSaveYes
End If

Include following code in OnCurrent event of your form:

fnResetTime1

Regards,

Mike
0
 

Author Comment

by:andrewreilly
Comment Utility
oops - i accepted too quick

this code is great but only answers half the question.

i want TimeVarForm1 to be reset if a keystroke is detected.  how do i do this?
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
Call fnResetTime1 anywhere in your application to reset it; if you enter it directly property sheet, use as:

=fnResetTime1()

I think you need if OnActive, OnCurrent, OnKeyPress and LostFocus events of form only.

OnActive: when you come back to a form.
LostFocus: When you leave the form and working on another form.
OnCurrent: When you add a new record and it stays idle.
OnKeyPress: When you press on any key while the form has the focus.

Mike
0
 

Author Comment

by:andrewreilly
Comment Utility
thanks again Mike
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
You are most welcome.

Mike
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now