title: My excel userform becomes unresponsive the next time I load it
body: <p>I have two forms, a login form to authenticate users to enter the system and a main form to work with if the authentication is successful. I work with an access database to search for the valid users and also to populate lists in the main form.</p>
  
  <p><a href="https://i.stack.imgur.com/nvHhR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nvHhR.png" alt="The user form for authentication"></a></p>
  
  <p>And here is the code for that:</p>
  
  <pre><code>Private Sub CancelCommandButton_Click()
      CloseDatabase
      Unload Me
  End Sub
  
  Private Sub ConfirmCommandButton_Click()
      ...
  
  End Sub
  
  Private Sub UserForm_Initialize()
      ConnectDatabase
  End Sub
  
  Private Sub OpenMainForm()
      Unload Me
      MainForm.Show
  End Sub
  
  Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
      If CloseMode = vbFormControlMenu Then
          Cancel = True
      End If
  End Sub
  </code></pre>
  
  <p>And here is the code for managing main form load-up and close:</p>
  
  <pre><code>Public Sub UpdateControls()
      PopulateUserList
  End Sub
  
  Private Sub UserForm_Activate()
      sTag = Split(Me.Tag, "|")
  
      If sTag(0) &lt;&gt; "1" Then
          Me.MainFormMultiPage.Pages(0).Enabled = False
          Me.MainFormMultiPage.Value = 1
      Else
          Me.MainFormMultiPage.Pages(0).Enabled = True
          Me.MainFormMultiPage.Value = 0
          UpdateControls
      End If
  
      UserLabel1.Caption = sTag(1)
      UserLabel2.Caption = sTag(1)
      UserLabel3.Caption = sTag(1)
  End Sub
  
  Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  
      If CloseMode = vbFormControlMenu Then
          ' Tip: If you want to prevent closing UserForm by Close (×) button     in the right-top corner of the UserForm, just uncomment the following line:
          ' Cancel = True
  
          Dim answer As Integer
          answer = MsgBox("ÂíÇ ãØãÆäíÏ ˜å ãí ÎæÇåíÏ ÇÒ ÓÇãÇäå ÎÇÑÌ ÔæíÏ¿",     vbYesNo + vbQuestion, "ÎÑæÌ ÇÒ ÓÇãÇäå")
  
          If answer = vbYes Then
              CloseDatabase
          Else
              Cancel = True
          End If
      End If
  
  End Sub
  
  Private Sub UserForm_Terminate()
      loginForm.Show
  End Sub
  </code></pre>
  
  <p>When I close the main form by clicking 'X' button, the login form reappears and the main form is closed; But when I login again (preferably using the same credentials) the main form is displayed but totally unresponsive (No list population, 'X' button doesn't work or any other controls in the form).</p>
  
  <p>What should I do? Does the code in the UserForm_CloseQuery() unload the main form and all of its macros and I can't get the required events back to function or am I missing something?</p>
  
  <p>It's not a time I started coding VBA and I can't make the head or tail of it easily when new problems arise. Any help would be appreciated. Thanks</p>