Solved

Access: Make timer on form

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

738 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