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
Solved

Detect idle time and close a form automatically

Posted on 2003-10-23
5
503 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 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

808 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