Solved

Detect idle time and close a form automatically

Posted on 2003-10-23
5
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 50 total points
ID: 9612533
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
ID: 9631727
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 34

Expert Comment

by:Mike Eghtebas
ID: 9631763
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
ID: 9637479
thanks again Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 9637611
You are most welcome.

Mike
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

617 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