Wait or Pause Command?

  • Thread starter Montana DOJ Help Desk
  • Start date
M

Montana DOJ Help Desk

Word 2000

I am thinking about writing a macro that will display a 10 second count down
in a user form. In order to do that, I would have to update the form once a
second. I took a quick stab at making this work, but I ran into two
problems. 1) I was trying to use the Update method with my user form, and
that was causing a problem, and 2) I could not find the command in the VBA
Help to make my code wait for 1 second between each update. What I tried
initially was similar to the following:

Dim MyDialog as Dialog

Set MyDialog = ufCountDown
For Seconds = 10 to 1 Step - 1
lblCountDown.Caption = "Seconds remaining: " & Seconds
MyDialog.Update
< Command to wait 1 second>
Next

Can someone help me get this working?

-- Tom

State of Montana
Department of Justice Help Desk

"Making the world a safer place."
 
H

Helmut Weber

Hi Tom,
just one possible way, using the caption, though.
---
Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Sub Makro1()
UserForm1.Show
End Sub
---
Private Sub UserForm_Activate()
Dim i As Integer
Me.Repaint
For i = 10 To 1 Step -1
Me.Caption = Str(i)
Sleep 1000
Next
End Sub
You may want to disable some or all controls on the form
in addition beforehand. Otherwise, if the user has clicked
on some commandbutton during the countdown,
the command would be executed after waiting.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
M

Microsoft

Helmut,

Thanks for the reply. I'll give your suggestion a try. And good point
on disabling the other form controls too--I had not thought about that,
but it makes perfect sense.

After getting home last night, I was racking my brain over this question
and I came up with the name of the Timer function. I looked that up in
the VBA Help, and it looks like that is the command that I was looking
for. Also, when I looked up the Timer function, one of the related
commands that came up was the OnTime method, which might also be of some
use in solving problems like this one.

--Tom
 

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

Top