?
Solved

Detect idle time and close a form automatically

Posted on 2003-10-23
5
Medium Priority
?
515 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 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