Timer

Bay

New member
Local time
Today, 13:59
Joined
Feb 8, 2000
Messages
5
Anybody have an example code to create a timer function in a form?
 
You need to give us more information on exactly what you are trying to do. There is a timer built in to each form that can be accessed by using the On Timer event of the form.

RDH
 
What I want from the timer is when a record is created the timer is started and when you click on a closed check box the time that the record was open will appear
 
If I understand what you are trying to do, I think the best thing for you to do is add a Date/Time field, called something like "CreateTime", and set it's default value to "Now()". This will store the the creation date/time for every new record created. Then all you have to do to find out when a record was created is to reference the CreateTime field. In this case, there really isn't a "timer" used, you are simply recording when the record was created.

Once you have the CreateTime of the record stored, you could also do calculations with it, for example, if you want to know how many minutes ago a record was created. In this case, you could use the VBA DateDiff function to calculate the difference between when the record was created and the current time.

Did I answer your question?

Jamie
 
Jamie,

How do I use the DateDiff function?

I want the Difference of time to be calculated when I click on a 'closed' check box(signifying a trouble call being completed). I have a field for the time when the record is opened, 'Time' and the filed that I want the calculated time is called 'Duration of Call'. How can I use a DateDiff function with click on the 'closed' check box?
 
Sorry it too me so long to get back to you.

The DateDiff function subtracts one date or time from another and returns a value measured in anything from seconds to years. The DateDiff function is formatted like:

DateDiff("x", Date1, Date2)

In this function, x sets what interval you would like returned. Ex. to have a return value measured in seconds, substitute a "n" for the "x"; for a return in months, substitute an "m". Lookup DateDiff in the help file to see all the interval options. Date1 and Date2 are the variables you want to calculate the difference of.

In your case, you want to calculate the difference between the time the record was created and the time the records was "closed." If, for example, you had a field called CreateTime that had the creation time of the record, a field called CloseTime that had the time the call was completed and wanted to display the difference between the two in minutes, the DateDiff Function would look like:

DateDiff("n", [CreateTime], [CloseTime])

You mentioned that you had created a field called 'Duration of Call' to store the calculated value. I don't suggest storing the calculation in this field. Instead, I would store the time the call was completed and run the DateDiff calculation whenever you need to know the Duration of the Call. In general, to keep your database streamlined, you don't want to store any information you don't have to, so if you can ever calculate a value, don't store it.

If you want to display the results of the calculation on a form or report, create a text box and in the Record Source property, instead of putting in a field name, put the DateDiff calculation in instead.

Hope this helps! Let me know if not!

Jamie
 

Users who are viewing this thread

Back
Top Bottom