Timer not being dispalyed and not able to use form??

D

DontKnow

Hi Guys,

I need help in showing the timer value to a text box as well the user can
still operate a form within the database, whilst the counter is counting down.

Here is my code for the Timer: (from the F1 menu)


Private Sub Alarm()

Dim PauseTime, Start, Finish, TotalTime

If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
PauseTime = 20 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
'DoEvents ' Yield to other processes.

Finish = Timer
TotalTime = Finish - Start
Me.Text30 = Fix(TotalTime) ' unable to see the value

Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If

End Sub

The problem here is that the user cannot see the value in the text box as it
is operating too fast, as well as the timer has the focus you cannot use he
dataabase until the timer is completed/finished.

(I can see the value if I step through using the F8 key!)
Any suggestions would be invaluable!!

Many thanks in advance!!

Cheers,
 
T

Tom van Stiphout

On Thu, 22 Apr 2010 17:54:01 -0700, DontKnow

You need to think more event driven rather than procedural. You want
to start a timer:
For example this one ticks once every second (if nothing else pressing
needs to get done) when a button is clicked:
private m_EndTime as Date
Private Sub cmdStartTimer_Click()
Me.TimerInterval = 1000
m_EndTime = DateAdd("s", 20, Now())
End Sub

Then in the Form_Timer interval you can update the display, as well as
compare the current time with the End Time, and stop the timer when
done.
Private Sub Form_Timer
If Now() > m_EndTime Then
Me.TimerInterval = 0
Else
Me.txtCurrentTime = Timer
End If
End Sub

-Tom.
Microsoft Access MVP
 
D

DontKnow

Hi Tom,

Thanks for your response!!

In your code you have :
private m_EndTime as Date
Private Sub cmdStartTimer_Click()
Me.TimerInterval = 1000

Is this correct??

Where should I place these pieces? Should they go into the "Form Open" event?

many thnaks for your input!!

Cheers
 
T

Tom van Stiphout

On Thu, 22 Apr 2010 22:33:01 -0700, DontKnow

THe first line goes in the Declarations section of your form.
The next two lines was me thinking you have a button named
cmdStartTimer where you would want to start the timer. I was assuming
the user clicks some button and the timer starts.

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using timer as Alarm clock 4
Understanding Timer Pause code 4
Understanding Timer Pause Code 6
Stop my timer 4
Self Closing MsgBox 6
save file 4
Timer to assess runtime 1
Make code aware of the workbook file name 3

Top