Understanding Timer Pause code

O

Owl

I have created the following Event Procedure for On Timer (the Timer Interval
is set to 10000):

Private Sub Form_Timer()

'On the forms timer event close the start-up form
DoCmd.Close acForm, "Diana'sStartUpForm"
'Open up the main switchboard form when the start-up form closes
DoCmd.OpenForm "Switchboard"

End Sub

I have subsequently created a Pause Button called Pause This Screen with the
following Event Procedure (which I don’t understand but copied it from the
Internet and modified it where I THOUGHT it needed to be modified to pause
for 30 seconds):

Private Sub Pause_this_screen_Click()
Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Pause this screen", _
4)) = vbYes Then
PauseTime = 30000 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If

End Sub

My first question is: What does the _4 mean?
My second question is: What do I need to do to modify the screen to pause
for 30 seconds (because it isn't working)?
My third question is: Does that mean it will pause for 30 seconds IN
ADDITION TO – or INSTEAD OF - the original 10 seconds as set on the timer?

I have added a “Continue to Main Menu†button which overrides the pause, but
would like the pause to be long enough to make the user have control of how
much time is spent on the StartUp screen.

Thank you for any help
 
A

Allen Browne

This one would let you specify a number of seconds:

Public Function Sleep(lngSeconds As Long)
Dim dtEnd As Date
Static bRunning As Boolean
If bRunning Then Exit Function
dtEnd = DateAdd("s", lngSeconds, Now())
Do While Now() < dtEnd
DoEvents
Loop
bRunning = False
End Function
 
O

Owl

Thank you for your response. Where would that code go? I tried it in the On
Click of the Pause This Screen button and couldn't get it to work.
 
O

Owl

In this particular instance, I don't actually want the user to put in how
many seconds. I want to pause for exactly 30 seconds (because there is an
Out as described above). However, I would very much like to know where your
code would go, because there could be other databases where I could use that.
Also I would appreciate an answer to my 3 questions in my first post in this
thread.

Thank you for any replies.
 
A

Allen Browne

Put the code into a standard module.

Then call it by setting your button's On Click property to:
=Sleep(30)

I'll let someone else answer your other threads: as you can appreciate, we
can't take them all on.
 

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


Top