Idle form mode change

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that is locked unless a button is pressed to put it in edit
mode. Is there a way to have the form change back to locked mode if no key
has been pressed for a certain time - say 2 minutes?

At the I am using the form's timer to turn it back every couple of minutes -
but this can arbritrarily lock the form while users are still entering data.

Any help would be appreciated.
 
PJ said:
I have a form that is locked unless a button is pressed to put it in
edit mode. Is there a way to have the form change back to locked mode
if no key has been pressed for a certain time - say 2 minutes?

At the I am using the form's timer to turn it back every couple of
minutes - but this can arbritrarily lock the form while users are
still entering data.

Any help would be appreciated.

At the moment, the Timer event is the best approach I can think of, but
you can get fairly sophisticated with it. For example, you can enable
the timer only when the "Edit" button is clicked (by setting
Me.TimerInterval to a nonzero value such as 120000), and disable it when
you lock the form again (by setting Me.TimerInterval back to zero). And
you can have logic in the Timer event that checks to see if the form is
Dirty, and only locks the form and resets if the form is not Dirty.
 
Declare a variable (dtLastKeyPress) as a date/time variable in the forms
declaration section.

Turn KeyPreview on for the form. In the KeyDown event of the form, reset
dtLastKeyPress = Now(). This won't handle mouse clicks, but will reset this
value every time a key is pressed.

As Dirk mentioned, when the edit button his clicked, set the timer interval
to something like 30 seconds (30000). In the timer event, check to see
whether Datediff("s", dtLastKeyPress, Now()) > some value. If it is, then
change the Allow Edits property of the form, set TimerInterval to 0. The
only problem with this is that if you have made changes during the edit
process, they will not have been saved.
 
Back
Top