Timer

G

Guest

I have a command button and when I click it I want to set the value of a text
box, but I want a time delay before it does it.

Private Sub Command50_Click()

(This is where I want it to wait for 5 or 10 seconds)

Text1 = 4000

End Sub

Can anyone give me an example of how to make this work
 
M

Michel Walsh

Hi,



Have a form scope variable:


Dim notBeforeDT AS Date


Under the button click, have something like:


notBeforeDT = DateAdd("s", 5, Now() )
Me.TimerInterval = 1000 ' each seconds



Under the form Timer event, have something like:

If Now() < notBeforeDT then Exit Sub
Me.Text1 = "4000"
Me.TimerInterval = 0 ' disable the timer





In fact, the "4000" is probably held in another form scope variable.


Hoping it may help,
Vanderghast, Access MVP
 
W

Wayne Morgan

Are you wanting to do something else while waiting? If not, then the API
function Sleep() should work well.

The declaration for the call is:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Place the line above in the Declarations section of a standard module.

Then to call it, you would simply pass the number of milliseconds you want
to wait.

Example:
Sleep(5000)
 

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