How to set default Values for a Userfrom and call the Userform

PETLECLS1

New Member
Joined
Nov 20, 2017
Messages
7
When I click the button that calls up the userform, the userform comes up, but none of the default values I have picked show. I am using Excel 2010.

How do I fix my code?
Code:
Sub NewTranslationRequest()'Fill Default Data
 OptionButton1 = True
 OptionButton2 = False
 OptionButton3 = False
 OptionButton4 = True
 OptionButton5 = False
 OptionButton6 = True
 OptionButton7 = False
 OptionButton8 = True
 OptionButton9 = True
 OptionButton10 = False
 OptionButton11 = True
 CheckBox1 = True
 CheckBox2 = True
 CheckBox3 = True
 CheckBox4 = True
 CheckBox5 = False
 CheckBox6 = False
 CheckBox7 = False
 
 'Clear previous data
 ComboBox1 = ""
 TextBox4 = ""
 TextBox1 = ""
 TextBox2 = ""
 TestBox3 = ""
UserFormNewRequest.Show
End Sub
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You need to set the values in an initialize event
Code:
Private Sub UserForm_Initialize()
OptionButton1 = True
OptionButton2 = False
OptionButton3 = False
OptionButton4 = True
OptionButton5 = False
OptionButton6 = True
OptionButton7 = False
OptionButton8 = True
OptionButton9 = True
OptionButton10 = False
OptionButton11 = True
CheckBox1 = True
CheckBox2 = True
CheckBox3 = True
CheckBox4 = True
CheckBox5 = False
CheckBox6 = False
CheckBox7 = False
End Sub
 
Upvote 0
If you want default values, you can set them at design time. Alternatively, you need to qualify the controls with the userform object
Code:
Sub NewTranslationRequest()'Fill Default Data
With UserFormNewRequest
.OptionButton1 = True
.OptionButton2 = False
.OptionButton3 = False
.OptionButton4 = True
.OptionButton5 = False
.OptionButton6 = True
.OptionButton7 = False
.OptionButton8 = True
.OptionButton9 = True
.OptionButton10 = False
.OptionButton11 = True
.CheckBox1 = True
.CheckBox2 = True
.CheckBox3 = True
.CheckBox4 = True
.CheckBox5 = False
.CheckBox6 = False
.CheckBox7 = False

'Clear previous data
.ComboBox1 = ""
.TextBox4 = ""
.TextBox1 = ""
.TextBox2 = ""
.TestBox3 = ""
.Show
end with
End Sub
 
Last edited:
Upvote 0
Thanks guys! I had to tweak it a little as I had a typo and added an extra option button. But the code works now! :)
Code:
Sub NewTranslationRequest()
'Fill Default Data
With UserFormNewRequest
.OptionButton1 = True
.OptionButton2 = False
.OptionButton3 = False
.OptionButton4 = True
.OptionButton5 = False
.OptionButton6 = True
.OptionButton7 = False
.OptionButton8 = True
.OptionButton9 = True
.OptionButton10 = False
.CheckBox1 = True
.CheckBox2 = True
.CheckBox3 = True
.CheckBox4 = True
.CheckBox5 = False
.CheckBox7 = False
.CheckBox8 = False

'Clear previous data
.ComboBox1 = ""
.TextBox4 = ""
.TextBox1 = ""
.TextBox2 = ""
.TextBox3 = ""
.Show
End With
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

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