Clyde has attended:
Access Introduction course
Access Intermediate course
Access Advanced course
Form Time-Out
How would I go about getting a form to auto-close after a set amount of time in a state of inactivity?
Form Time-Out In Access
Hi Clyde
To get you form to time-out after a certain amount of time do the following:
1. Create a macro that closes the required form
2. In the Forms Properties area select the Events tab
3. In the On Timer event select the macro created to close the form.
4. In the Time Interval section enter the time interval to close. (eg 30000)
NB For the Timer Interval 1,000 = 1 Second, 60,000 = 1 minute and 3,600,000 = 1 Hour
The timer starts when the form is opened.
Now the above Timer Interval value starts the timer as soon as the form opens and closes the form after the set time, whether it is inactive or not.
To overcome this as there is no Inactive event we need to keep reseting the clock on some Mouse and Keyboard actions.
To do this:
1. In the Key Press event select Event Procedure
2. Click the 3 dots to open the code window
3. Copy the following code and paste it in the code window:
Private Sub Form_KeyPress(KeyAscii As Integer)
Me.TimerInterval = 30000
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.TimerInterval = 30000
End Sub
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
Me.TimerInterval = 30000
End Sub
NB The code resets the Time Interval back to our example value of 30000, everytime a key is clicked, or the mouse wheel or the mouse is moved on the form.
If these events cease to occur after the predetermined time the system will close the form
Hope this helps
Carlos