Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a procedure with atimed event for a msgbox to pop-up 1

Status
Not open for further replies.

inso18

Technical User
Dec 30, 2006
147
IL
Hello experts. I'm trying to correctly combine a code for a command button, so when it is clicked a message box will appear after 3 seconds.

Can you explain how to do it?
Thanks a bunch.
 
inso18,

Here's one way:
Code:
Private Sub Command0_Click()
Dim TimeA As Date
Dim TimeB As Date
TimeA = Now
TimeB = DateAdd("s", 3, TimeNow)
Do Until TimeA >= TimeB
    TimeB = Now
    DoEvents
Loop
MsgBox "Three seconds have elapsed."
End Sub
HTH,

Ken S.
 
Oops, my goof. This will work better... ;-)
Code:
Private Sub Command0_Click()
Dim TimeA As Date
Dim TimeB As Date
TimeA = Now
TimeB = DateAdd("s", 3, Time[red]A[/red])
Do Until TimeA >= TimeB
    Time[red]A[/red] = Now
    DoEvents
Loop
MsgBox "Three seconds have elapsed."
End Sub
 
And another way:
Code:
Dim PauseTime As Integer
Dim Start As Single
Dim Finish As Single
Dim TotalTime As Integer

PauseTime = 3    [green]' Set duration.[/green]
Start = Timer    [green]' Set start time.[/green]
Do While Timer < Start + PauseTime
    DoEvents    [green]' Yield to other processes.[/green]
Loop
Finish = Timer    [green]' Set end time.[/green]
TotalTime = Finish - Start    [green]' Calculate total time.[/green]
MsgBox "Paused for " & TotalTime & " seconds"
 
And a 3rd way...

In the form's or module's Declaration section:
Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Then in your Sub:
Code:
Sleep 3000
MsgBox "Slept for 3 seconds."
HTH,

Ken S.
 
Thanks so much folks!
Eupher, this method looks neat!
 
Ah, oops, you've posted all the methods :)
 
If I may bother you again, those methods are good, but actually I need a time pause of miliseconds, lets say 0.5 a sec. The first and the second methods won't work with that, and the third method gives me a sand-clock and doesn't let me do anything in the waiting time.

I actually need this for causing a control to expand his .height in steps using loop, and on each step to be requiered, so I need those small time intervals to each step, so the changes of its height expansion could be seen. With the 3rd system I can't see the changes until the final change.

Is there a method that both can use milleseconds and not stop the system?

Much thanks,
Michael.
 
Allright, you can ignone my last message. Milliseconds can be used with the second way you've posted if Integer is replaced for Single.

Anyway, this thing of sliding-expanding the control is not so smooth in Access, the best method I can use on each step is me.requery, but this is offtopic...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top