Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Sleep Function 1

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
I have created a form that allows a user to edit a table, but not until they login with a username and password. Otherwise, the table cannot be edited, and is just used as a reference.

I wanted to set up a routine so that after a specified amount of time, the form will automatically log the user off in case they forget to do it themselves. I do not want unauthorized users editing these tables.

I searched around and came accross the following routine:

Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

This code is easily called from any other routine. My problem is that when the form calls this code, it prevents the user from doing anything else on the form. I would like them to be able to edit the table on the form for 5 minutes, then have it automatically log them off, but my computer is basically stalled while it waits for the specified time to end before it frees up again.

Is there a better way to solve this problem? Is there a way to use this function and still allow users to edit the table while it is running?

Thanks
 
Are you talking about the Form_Timer event?

I thought about that, but wouldn't I just be able to have something happen at a specified interval? Is there a way to start and cancel this event?
 
You can set the Timer Interval programatically, an interval of 0 means that the event will not run. Use 300000 for 5 minutes. If the form is to be closed, the interval becomes irrelevant.

It would be possible, with form level variables, to set an initial interval to warn the user and a second interval to log out.
 
Setting the timer interval programatically works well.

I just set it to 5 minutes when the user logs in, then set it to 0 when the user logs out or is automatically logged out after 5 minutes.

Thanks for pointing me in the right direction Remou!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top