title: Adding userform controls during runtime "Object variable or with block variable not set" error
body: <p>My code below is giving an error on the line</p>
  
  <p><code>Set VM = AP.VBProject.VBComponents("ViewManager").Designer.Controls</code>   </p>
  
  <p>I have looked up many examples of working code and cannot figure out how mine is set up differently to cause an error. </p>
  
  <p>The error is <code>Run-time error '91': Object variable or With block variable not set</code></p>
  
  <p>Thanks for any help.     </p>
  
  <pre><code>Private Sub btnAdd_Click()
      Dim View As String
      Dim FField As String
      Dim TField As String
      View = cmbView.Value
      FField = cmbFrmFld.Value
      TField = cmbToFld.Value
  
      'if it is the first add change one way, if after the first add change another
      If ViewManager.Height = 116 Then
          ViewManager.Height = ViewManager.Height + 64.5
      ElseIf frmViews.Height &gt; 116 Then
          ViewManager.Height = ViewManager.Height + 30
      End If
  
      Dim AP As Project
      Set AP = ActiveProject
      Dim lbl As MSForms.Label
      Dim VM As Object
  
      Set VM = AP.VBProject.VBComponents("ViewManager").Designer.Controls
      With VM
          Set lbl = .Add("Forms.Label.1")
      End With
  
      With lbl
          .Left = 6
          .Top = ViewManager.Height - 32
          .Width = 156
          .Caption = View
      End With
  End Sub
  </code></pre>