Have a look at the attached sample Database I've knocked up. The controls and code on the opening form would have to be incorporated into your main switchboard.
The Database is opened to the form.
- The 'Time Opened' control is set to Time() when the form is opened.
- The 'Timer' control counts in 1 second intervals since the time that the form was opened.
- The 'Seconds Open' control has its value set when the Exit button is pressed (calculates by subtracting the value of Time Opened from the latest value in the Timer control and inserts this into Table1)
- The value of the 'Seconds used before this session' control is taken from Query 1, which simply sums all values in Table1 - this will update every time the form is opened.
You can obviously hide these controls on your switchboard if you do not wich them to be viewed by the user.
Upon opening the Database, an autoexec macro is run which runs a function. This function determines how long the Database has been used for and if they have spent more time than you have allowed (the 2.0833333333334E-03 currently set in the code equates to 3 minutes), a message is displayed informing them that their trial period has expired and the Database is closed.
There are a couple of issues to address doing it this way:-
- You will have to disable Shift opening of the database as the autoexec macro will not be run (code to achieve this can be found here - http://www.access-programmers.co.uk/forums/showthread.php?t=51479)
- You will have to password protect the Back End Database where Table1 will be held and hide the linked table and Query1 in the Front End so that the user cannot delete/edit the recorded time.
- You would have to distribute it as an .mde file so that the user could not view the code and therefore have the ability to edit the time allowed.
I have set the 'Seconds used before this session' control's source query to equal 2 minutes and 55 seconds so that you can see the form being used. All you have to do is keep it open for 5 seconds or more, then Exit and re-open to see the function working.
There are probably other ways of doing this, but this was the best I could come up with. Let me know if you need anything explained further.
EDIT - You'll also need to disable the Application Close button to ensure the user exits the Database using the custom Exit button. Code to achieve this can be found here -
http://support.microsoft.com/kb/245746