title: How to check if a userform is closed with "X" Windows button?
body: <p>There is a sub, it creates a <code>CourtForm</code> userform and then takes a data from it. The problem appears when said form is closed prematurely, by pressing "X" window button and I get a runtime error somewhere later. For reference, this is what I'm talking about: </p>
  
  <p><a href="https://i.stack.imgur.com/8RkiO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8RkiO.png" alt="enter image description here"></a>
  In my code I tried to make a check to exit sub:</p>
  
  <pre><code>Private Sub test()
  
      'Create an exemplar of a form
      Dim CourtForm As New FormSelectCourt
      CourtForm.Show
  
      'The form is terminated at this point
  
      'Checking if the form is terminated. The check always fails. Form exists but without any data.
      If CourtForm Is Nothing Then
          Exit Sub
      End If
  
      'This code executes when the form proceeds as usual, recieves 
      '.CourtName and .CourtType variable data and then .hide itself.
  
      CourtName = CourtForm.CourtName
      CourtType = CourtForm.CourtType
      Unload CourtForm
  
  
      'Rest of the code, with the form closed a runtime error occurs here
  
  End Sub
  </code></pre>
  
  <p>Apparently the exemplar of the form exists, but without any data. Here's a screenshot of the watch:</p>
  
  <p><a href="https://i.stack.imgur.com/zOBcY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zOBcY.png" alt="enter image description here"></a></p>
  
  <p>How do I make a proper check for the form if it's closed prematurely?</p>