Form initialization

Before we begin to use forms we need to initialize them. This means adding a set of values to the controls and setting the default values. Initializing values is done in the subroutine from which we start the the Form. Show method to display the form. After it opens, the user will be able to enter the desired values, and most importantly, it will be able to select the values instead of always input them as plain text.

The default value of the optional fields is entered by setting the Value property to True. In the same way, we could change the name of a label or assign a value to the text input field.

UserForm2.OptionButton1.Value = True

When we add data to the list we will most often do it within the loop. In this particular case we enter the years from 1915 to 2015 using the AddItem method.

For i = 1915 To 2015
   UserForm2.ComboBox1.AddItem i
Next i

In the end, when we merge these pieces of code, we get a subroutine for the form initialization.

Sub Init()

Dim i As Integer
UserForm2.OptionButton1.Value = True
For i = 1915 To 2015
UserForm2.ComboBox1.AddItem i
Next i
UserForm2.Show

End Sub