Solved

Access: Make timer on form

Posted on 2008-10-02
3
313 Views
Last Modified: 2013-11-28
When  a user clicks on a button (Titled: "Process") on my form (titled: "Form1") a bunch of functions run. They can take awhile so I how do I make it so that a box appears on my form that counts the number of minutes and seconds that pass while my functions run. (This way users can see how much time it took to do the process)

i.e. User presses the button titled: "Process"
1 second
2 second
3 second
4 second
.
.
.
5 minutes 20 seconds   (
0
Comment
Question by:ouestque
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 500 total points
ID: 22627749
There are two actual requests here --
 1) Show the total time that a process took.  This can always be done easily.

 2) Show a timer that advances in seconds while the process runs.  This depends on a few factors: if it is a single, long-runnning query, you can't interrupt the query to update the screen with each passing second. If the process a series of function calls, add a DoEvents between each separate call.  If you have looping structure, you can add something like:
For i = 1 to 100000

'do stuff

If i mod 1000 = 0 Then
  DoEvents
End If


and adjust the 1000 value to give your form to update the counter smoothly.

'Make module-level declarations in your form:
Dim lngSec As Long
Dim sngStart As Single
---
'Within the cmdProcess Click event

Private Sub cmdProcess_Click()
'save the starting time as number of seconds since midnight

sngStart = VBA.Timer
Me.TimerInterval = 500
'I'd try 500ms -- how often the form gets painted depends on the how busy the

'call your functions here

'be sure to use DoEvents between function calls and within loops to cede 'processor time to updating the screen

'Your functions have completed

Me.TimerInterval = 0
Me.txtDisplay = "Done after " & Me.txtDisplay
End Sub
------------
'within the form's Timer Event


Private Sub Form_Timer()
lngSec = CLng(Timer - sngStart)

If lngSec < 60 Then
  Me.txtDisplay = lngSec & " seconds"
Else
  Me.txtDisplay = lngSec \ 60 & " minutes " & lngSec Mod 60 & " seconds"
End If

End Sub
----------



HTH,

Pteranodon
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question