Opening a userform, entering text in a textbox, closing it and display it after an interval of time...

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
The title explains it.
Userform1 has Optionbutton1 with a label of 10 seconds.
A button on the worksheet opens the form initially.
All I want to do is click the button, open the form, enter ABC in Textbox1, click Optionbutton1(would open it in 10 seconds), click an OK button on the form to Unload it, and have it display again 10 seconds later with the same text ABC in Textbox1.
I know this is simple but I can't get the code to work this way.

Thanks for anyone's help.
cr
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:
Put this code on the UserForm1 code page, under the OK button click
Code:
Private Sub btn_OK_Click()
Call runme
End Sub

In a module, place this code
Code:
Sub runme()
Dim newHour, newMinute, newSecond, waitTime, GetText
Dim x As Integer
[COLOR=#00ff00]'get the text from the user box[/COLOR]
GetText = UserForm1.TextBox1
[COLOR=#00ff00]'see if the Option Button is set[/COLOR]
If UserForm1.OptionButton1 = True Then x = 10 Else x = 0
[COLOR=#00ff00]'guess what this line does[/COLOR]
Unload UserForm1

[COLOR=#00ff00]'Set the wait time[/COLOR]
Application.Wait (Now + TimeValue("0:00:" & x))

[COLOR=#00ff00]'set the textbox to show in the textbox back to what you got above[/COLOR]
UserForm1.TextBox1 = GetText
UserForm1.Show


End Sub
 
Upvote 0
Try this:
Put this code on the UserForm1 code page, under the OK button click
Code:
Private Sub btn_OK_Click()
Call runme
End Sub

In a module, place this code
Code:
Sub runme()
Dim newHour, newMinute, newSecond, waitTime, GetText
Dim x As Integer
[COLOR=#00ff00]'get the text from the user box[/COLOR]
GetText = UserForm1.TextBox1
[COLOR=#00ff00]'see if the Option Button is set[/COLOR]
If UserForm1.OptionButton1 = True Then x = 10 Else x = 0
[COLOR=#00ff00]'guess what this line does[/COLOR]
Unload UserForm1

[COLOR=#00ff00]'Set the wait time[/COLOR]
Application.Wait (Now + TimeValue("0:00:" & x))

[COLOR=#00ff00]'set the textbox to show in the textbox back to what you got above[/COLOR]
UserForm1.TextBox1 = GetText
UserForm1.Show


End Sub


Hi Bill and thanks -this does work. The problem I have had is with this line: Application.Wait (Now + TimeValue("0:00:" & x)) - it merely SUSPENDS not STOPS(caps fjust for emphasis) execution. The little turning circle for lack of a better term keeps turning until the time is reached before redisplaying Userform1. I really want to STOP then RESTART some sort of a timer. What happens when we turn off our laptops? Any code of this .Wait type won't workbecause the session ends when the computer is turned off.


Would you know how to make Userform1 display(pop up) on say 01/17/2017 at 5:30 AM and display a previously saved Textbox1 message ?

The ideal : a Listbox1 with Times in 30 minute increments combined with a DTPIcker1 calendar dropdown to redisplay a Userfrom1 on ANY future date AFTER the computer is turned off. The code would grab both time and date and displaty Userform1 on that future time and date.

What other way than listing the Time and future calendar date on a separate sheet and searching for that time and date after the computer is turned on again and displaying the form again at the appropriate time - is there, if there is another simpler way ? Can you look at this when you have a chance and let me know?

Thanks for all your help.
cr
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top