title: How to reference userform click events in VBA
body: <p>I have a userform called 'dataBox' which is shown when the user clicks a command button. The user then inputs data and presses an OK command button on the userform to submit the data.</p>
  
  <p>What I am struggling with and what i need to happen is this: If the user clicks the OK button on the userform, a sub called category2 runs. If the user clicks 'X' nothing happens.</p>
  
  <p>here is my command button code</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  dataBox.Show
  If dataBox.Controls(okCommandButton_Click) Then
  category2 Range("A1")
  End If
  
  End Sub 
  </code></pre>
  
  <p>The line </p>
  
  <pre><code>If dataBox.Controls(okCommandButton_Click) Then
  </code></pre>
  
  <p>is completely wrong and is the latest attempt at referencing when the ok click event fires but hopefully it is clear what I am trying to do. i have scoured the web for the answer and can't get it to work! Thanks.</p>