Solved

Access: Make timer on form

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now