Wait for action

J

Johan

Hallo!

I want to make a macro that show a userform with a button.
If the user have not clicked the button within 15 sec I want the code to
continue.
If the user click the button the code will end.

Thanks for any help!

Johan
 
J

joel

What closes the userform is the HIDE method. Normally you put the HID
into the click function but you can put it anyplace in the code. Yo
need to start a timer function when you open the form in an initializ
routine. and stop the timer when you close the form. the Time
Procedure must be in a module, not in the userform. You also need t
stop the timer if the button is pressed.

below is the module code

Sub test()

UserForm1.Show
Call nextsub
End Sub

Sub my_procedure()

UserForm1.Hide
Call nextsub

End Sub


-----------------------------------------
Put this code into the userform


Sub Userform_Initialize()

Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"

End Sub

Private Sub CommandButton1_Click()
'code to stop the timer if the button is pressed.
Application.OnTime EarliestTime:=Now, _
Procedure:="my_Procedure", Schedule:=False

End Su
 
J

Johan

Thanks for your help joel, however the code goes to Error and gives the
following message:

Run-time error '1004':
Metode 'OnTime' of Object'_Application' failed

Any help on that?

Thanks
Johan

joel skrev:
 
J

joel

Make sure the code matches exactly what appeas in the posting. I full
tested this code with 2003. The Procedure Name "My_Procedure" on th
line and the procedure code in the Module must match.

I tried to duplicate the error and cannot which make me believe th
problem is a simple typo error.


Try typing "application." without the double quotes (with a period a
the end) and check in the pop up window to see in "ONTIME" appears.
want to see if all the libraries are installed on your PC
 
Top