Set a Maximum Locking Interval for a Record

Problem

You’ve employed pessimistic locking on your application’s forms to prevent two users from making changes to the same record at the same time. Sometimes, a user will lock a record for an excessive period of time; for example, he might start to edit a record and then get a long phone call or leave for lunch without saving or canceling his edits. Is there any way to limit how long a user can lock a record and time out the user when the locking time limit has been exceeded?

Solution

There’s no built-in database or form option for “maximum record lock interval,” but you can create your own record lock timeout feature by making use of the form’s Timer event. This solution shows you how to create such a facility using an event procedure attached to the form’s Timer event.

To add a record lock timeout feature to your own application, follow these steps for each form for which you wish to enable this feature:

  1. Open the form in design mode, and add to the form an unbound text box named txtMessage that will be used to display the countdown message. This control should be at least 3.45” wide and 0.1667” high. On the sample form, we have placed txtMessage in the form’s footer, but you can place it anywhere you’d like.

  2. Change the form’s TimerInterval property to 1000. This will cause any code attached to the form’s Timer event to be executed every 1,000 ms (or 1 second).

  3. Create an event procedure attached to the form’s Timer event. Figure ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.