Using a timer (with Start, Pause, and Stop) to count length of going thru the form

gjh

Registered User.
Local time
Today, 16:58
Joined
Feb 3, 2009
Messages
64
Hi

I need to create a timer (in minutes and second) in a form that has the ability to "start" and "Pause" the length of the process with 1 or 2 buttons next to the timer.

when the process is finished, i need to record the length of the process in a table by clicking the "Save" button.

i have created a start time "now()" but not sure how to pause in between the process. i think i may need few test boxes to do this.
 
Depending the the precision you require, can you not just use the form timer event? It is not 100% accurate, but I suspect you will get a fairly good result if you only want seconds.

The code below assumes you have a form with start, pause and stop buttons, plus a textbox to display the running total.

Code:
'decare a local variable to hold total
 
Dim lngTotal As Long
 
Private Sub cmdPause_Click()
    'pause the timer
    Me.TimerInterval = 0
End Sub
 
Private Sub cmdStart_Click()
    'start timer
    Me.TimerInterval = 500
End Sub
 
Private Sub cmdStop_Click()
    'stop the timer, display value and reset
    Me.TimerInterval = 0
    MsgBox ("Total Time: " & lngTotal)
    lngTotal = 0
End Sub
 
Private Sub Form_Timer()
    'increment timer
    lngTotal = lngTotal + Me.TimerInterval
    'display the current duration (in milliseconds) in a textbox
    'format lngTotal to support whatever level of precision you need
    Me.txtTimer = lngTotal
    DoEvents
End Sub
 
Hi CameronM

unfortunately, im new to access and not sure about coding or VB in access.

i have no clue about the coding that you posted. if possible, i would like my project to be done using access functions only and try not to use coding as much.

i like the idea of using the "form timer event" but not sure exactly how to use it. can you please show me an example or would you like me to show you what i have done?

i would like the timer to count minutes and seconds. eg. 4:25
and a button next to it that says "Start/Pause" or maybe two buttons. if you know what i mean!

Thanks!
 
that is exactly what i need!
thanks Wayne!

i have noticed that the text boxes says "unbound"
looks like every button has a coding in it. i've totally no clues what you have written in the code!

i really appreciate the info though, thanks again!
 
i have been looking into the code and wondering, is it possible to combine the minute and second into 1 field (instead of 2 separate boxes)?
 
maybe this timer is way too advance for me.
i dont understand how you have created the code.

i think i will try to play with the code to make it simpler.
sorry, i dont mean to be rude or anything like that but i want to be able to understand what im using.

is it possible to change the properties for the timer into time format, eg. min:sec 14:26?
 
i have been looking into the code and wondering, is it possible to combine the minute and second into 1 field (instead of 2 separate boxes)?

Just add another text box to the form and in the Control source put;

Code:
=[txtActualMinutes] & ":" & [txtActualSeconds]
or
Code:
=[txtTotalMinutes] & ":" & [txtTotalSeconds]

or add two text boxes and use both depending on what you want to show. You could then hide the other text boxes.
 
Hello John

thanks for the advice! i got it working!
 
Hi

I added the timer in my Call Integrity form and did a bit of modification to the timer.

when i run the form, the timer starts automatically! can someone show me how to disable the timer auto start thing?

secondly, when i save the record, it gives me an error mesage:

"the value you entered isn't valid for this field."

Im pretty sure that i have filled in the mandatory info! maybe it's clashing with the time but again im not entirely sure as i have no coding experience.

would it be easier if i add a clock instead of a timer. (if you know what i mean!)

thanks for your help in advance!
 
sorry, i cant show you my work as the file size is too large! nearly 1MB!
but if you would like to see the file, pls foward your email add to me and i will send you an email with the attachment!
 
g,

Not to worry.

Glad you have it working.

If you realy wanted to post it ...

1) Compact/Repair
2) Zip into a file
3) Attach to your next post

See ya g,
Wayne
 
Hi Wayne

not sure what do you mean by "compact/repair".
 
gjh,

Databases tend to "bloat".

A database can swell to a very large size with a bunch of unwanted junk.

Tools --> Database Utilities --> Compact/Repair

Nowadays, that's a little "old school", but that will bring your database
back to the size that you'd expect.

Do a Google on "Database bloat" and I bet that they'll be talking about
Access.

Wayne
 
wow, it shrinked down from about 9MB to about 1.3MB before zipping the file.

pls see attached!
 

Attachments

you are right, Wayne.
the first link on google search is about access product!
funny that it remembers the deleted stuff and the spaces.
i will use that compact/repair regularly then if i need to share a file with someone else!
 
gjh,

Never really tried the Google thing. Not a surprise though.

Hope to see you again here,
Wayne
 
have you looked at the tIMER function - this just records seconds (including fractions)

so just

Code:
starttime =timer
do stuff
endtime = timer

diff = endtime-starttime
msgbox("elapsedtime = " & (diff)\60 & " minutes  " & diff mod 60 & " seconds")
 
Hi Gemma

where do i put the code in? sorry, i have no coding experience. im new to access!
 
gjh,

when i run the form, the timer starts automatically! can someone show me how to disable the timer auto start thing?

If you don't want the timer to start when the form opens, you need to set the Timer Interval in the form properties screen to 0.

You then need to decide when to start the timer. This will depend on your business requirements. One option would be to start the timer when you select a name from the combobox.

add this code to the Name combobox
Code:
Private Sub Name_AfterUpdate()
    'start the timer for this call
    Me.TimerInterval = 1000
End Sub

then add this code to reset the value back to zero every time a record opens (eg you want it to be zero when you move between records, or create a new record)

Code:
Private Sub Form_Current()
    'set the timer to zero for each record
    Me.TimerInterval = 0
End Sub

Alternatively you can add a button labelled "Start" to set the timer interval, but that would take away the automation and no doubt users would forget to start timing the call.
 

Users who are viewing this thread

Back
Top Bottom