Raffigee
04-05-2003, 06:57 AM
Hey there,
I was just wondering if it's possible to set a timer on a userform?
I want the userform to appear but disappear in say five seconds.
Can i use the following code in a certain way ?
Sub Button2_Click()
Application.OnTime Now + TimeValue("00:00:05"), "test"
End Sub
Sub test()
userform1.hide
End Sub
thank you
italkid
04-05-2003, 08:48 AM
With a little modification you could use something like this :
Private Sub CommandButton1_Click()
Dim Count As Integer
For Count = 30 To 1 Step -1
Range("A1").Value = Count & " Seconds..."
Application.Wait Now + TimeSerial(0, 0, 1)
Next Count
End Sub
Raffigee
04-07-2003, 05:55 AM
Thanks for the help Italkid but my question was:
How can i make a userform disapear using a timer ?
I tried your code and it doesn't work i put it in the userform ( Activate ) or ( Initialize ) and no result. I'm sure there's a way but how ???
Any help
Here's one way, but it seems somewhat eratic.
Sub Test()
UserForm1.Show
End Sub
Sub UnloadForm()
Debug.Print "UnloadForm was called"
Unload UserForm1
End Sub
Private Sub UserForm_Activate()
Application.OnTime Now + TimeValue("00:00:05"), "UnloadForm"
End Sub
If you run the macro called Test, the form will be loaded and then unloaded 5 seconds later.
italkid
04-07-2003, 07:20 AM
Like this ?
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:05"), "HideForm"
UserForm1.Show
End Sub
And in a Module
Sub HideForm()
Unload UserForm1
End Sub
Like this ?
Yes, that should work, I think.
Raffigee
04-07-2003, 07:48 AM
Thanks Mill,
but now i have another problem...the userform goes away but also it stop from executing the rest of the code..
just to put you guys in the context.
It's a game. userform shows
the player bets on a horse but here's the problem: I want to give him only about 20 seconds to choose but after that the code has to continue. validate the results, calculate stats, etc.
so unload userform doesn't work out for this situation.
I simply want to do a hide like if i press on a command button.
Is there a way ?
Where is the code that is being stopped?
You could just do Userform1.Hide instead of unloading it.
Raffigee
04-07-2003, 08:23 AM
Thanks a lot Mill I think it works :) :D :)