Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access: Make timer on form

Posted on 2008-10-02
3
Medium Priority
?
319 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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