Solved

Access: Make timer on form

Posted on 2008-10-02
3
311 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
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

830 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