title: Wanting to allow only 2 of the same form to be opened VB6
body: <p>So far i have some code that allows a user to Hit F1 which loads a new form of the same properties and then hides the one the first one they had up, Hitting F2, allows the user to close the newly opened form and show the one they opened first. I would like a restriction that allows the user to open only 1 extra form if they hit F1 with 2 of the same forms open then a messagebox appears telling them to close the second form first otherwise allow it to be opened. </p>
  
  <p>Here is what i have so far.</p>
  
  <pre><code> Private Sub Form_Load()
  
   End Sub
  
   Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  
      Select Case KeyCode
  
          Case vbKeyF1
          'hides the current form
              Me.Hide
          'loads a new form with the same properties
              Dim f As New Form1
              Load f
          'shows this new form
              f.Show
          'says that the second form is open
              fOpen = True
  
          Case vbKeyF2
          'closes the second form
              Unload Me
          'says that the second form is closed
              fOpen = False
          'shows the first form you were on
              Form1.Show
  
      End Select
  End Sub
  
  Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
  
     'if your hitting "X" on second form then just close form2
     If fOpen = False Then
     Form1.Show
     Else
     'if your hitting "X" on main form close everything
     Unload Me
     End If
  
  End Sub
  </code></pre>
  
  <p>Maybe something like if fOpen = true then disallow the user to hit F1? Not quite sure, but im close.</p>