title: How to initialize a combo box in a form?
body: <p>My understanding is that initialization code runs when I invoke &quot;New UserForm2&quot;.</p>
  <p>Below is the code that invokes a New userform and the code associated with the userform.</p>
  <p>I stepped through with the debugger and watched it execute the initialization code, but it has no affect on the form. The combo box is still blank.</p>
  <pre class="lang-vb prettyprint-override"><code>If TabID = &quot;5 Client List&quot; Then
      With New UserForm2
          .Show
          If Not .IsCancelled Then
              If InStr(TarSheet, &quot;5.1&quot;) Then
                  Call General_Transfer(TabID, TarSheet, 28, &quot;Yes&quot;)
              End If
              TarSheet = &quot;&quot;
          End If
      End With
      Exit Sub
  End If
  </code></pre>
  <pre class="lang-vb prettyprint-override"><code>' UserForm2 Code
  Option Explicit
  '@Folder(&quot;UI&quot;)
  Private cancelled As Boolean
   
  Public Property Get IsCancelled() As Boolean
      IsCancelled = cancelled
  End Property
   
  Private Sub CommandButton1_Click()
      TarSheet = Me.ComboBox1.Value
      Hide
  End Sub
   
  Private Sub CommandButton2_Click()
      TarSheet = &quot;&quot;
      OnCancel
  End Sub
   
  Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
      If CloseMode = VbQueryClose.vbFormControlMenu Then
          Cancel = True
          OnCancel
      End If 
  End Sub
   
  Private Sub OnCancel()
      cancelled = True
      Hide
  End Sub
  
  Private Sub UserForm_Initialize()
      UserForm2.ComboBox1.AddItem &quot;5.1 Client List LTS&quot;
  End Sub
  </code></pre>