Creating real-time timer with save and continue

mcdhappy80

Registered User.
Local time
Today, 22:58
Joined
Jun 22, 2009
Messages
347
Hi. I want to create a mechanism that starts a timer the first time You run the application and then each time You reopen the program it continues on the previous time and when it comes to the, lets say, 1 hour of work it blocks itself and stop working.
Now, I know how to create a blocking part, but what I don't know how to create a timer that will run seconds realtime and be able to save the last time the appication was closed.
If anyone could shar ideas wrom where to start I would be gratefull.
Thank You.
 
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
 

Attachments

Last edited:
Have a look at the version I've attached to this post. The previous version only checked the time open when the Database was opened, which meant that the user could use the system for as long as they wanted if they didn't close it down.

The new version checks the time open every second and as soon as it reaches 3 minutes the message is displayed and the Database closed.
 

Attachments

Last revision - this version now shows the user the time they have remaining. Feel free to ask any questions.

EDIT - also in this version you can change the time allowed by simply overtyping the value held in Table2
 

Attachments

Last edited:
you need to save the accumulated time somewhere. the hard part is deciding where - (eg a local table, a linked table, a text file, the registry) and concealing this info from the user.

I am sure dbdamo's example does something like this.
 
In my example the duration of each session is added as a new record into a local table (but this should be changed to a linked table when the Database is split and the Back End password protected so the user cannot access it). The total duration is calculated in a query by summing the individual sessions.

As you say, this needs to be hidden from the user so my suggestion was to hide the linked tables and queries used - while I am aware that anyone with a good understanding of Access will know how to unhide them, if other linked tables and queries are left unhidden there would be no reason for the user to assume that any were hidden and they would assume that the calculations were performed within VB, which if the Database was distributed as an .mde file would not be accessible.

By disabling F11 and shift open the user should not be able to access the Database window which should mean that they can't get into your tables and queries to edit values anyway????

Anyway, as I said in my original post there are probably numerous ways to achieve what is required, this was just my best effort and I am still a relative beginner...
 
I'm getting couple of errors when I try to open this database. I also had same problem with the first posted version.
How do I open this?
Thank You
 

Attachments

Last edited:
I can't d/l the zip file you've posted from work - crappy restrictions.

Any chance you can post the error messages and say when they occur???
 
I can't d/l the zip file you've posted from work - crappy restrictions.

Any chance you can post the error messages and say when they occur???

No, because there are 7 pictures (screen capture), from within the database also, and on them You can see that there are no tables, queries, and the code won't work, because it's missing some functions. You'd best download the zip and see what I'm talking about.
 
If you shift open the Database then open VBE and go to Tools>References and uncheck any that say MISSING that should sort out the 1st error.

The version of Access you are using appears to be preventing the AutoExec macro from running - is there a way of turning off this disable macro security?
 
If you shift open the Database then open VBE and go to Tools>References and uncheck any that say MISSING that should sort out the 1st error.

The version of Access you are using appears to be preventing the AutoExec macro from running - is there a way of turning off this disable macro security?

Yes there is, and I enabled all macros but then the error was on Form1_Open,
Code:
Me.TimeOpened = Time()
, can't find project or library.
The thing i'm missing reference to is microsoft office xp web components, now, I have office 2007 installed, can I upgrade the installation? Does office 07 contain this library? Maybe I turned it of during installation and that's why its missing? How do I turn it off?
 
No probs, just ask if you need any more help.
 
I have another question that involves the time that has passed and where it is stored.
Which is better candidate for storing the time, registry or created database property?
I want to be able to save time but in such "format" that it cannot be changed outside my program.
If I save it in the registry key or database property can I make the property or the key read-only and change the read-only property from my program when I want to save new time?
Can someone share any idea on this thought? I don't want to save time to database table is there a better non-modifyable place?
Thank You
 
i shouldnt think there is anywhere that is non-modfiable - all you can do is make it hard to find, and hard to use. eg you could add some encryption, so even if a user finds it, he wouldnt know how to change it.
 

Users who are viewing this thread

Back
Top Bottom