これまでのところ、ユーザーが F1 を押して同じプロパティの新しいフォームをロードし、F2 を押すと、ユーザーが新しく開いたフォームを閉じて表示できるようにするコードがいくつかあります。彼らは最初に開いた。ユーザーが同じフォームを 2 つ開いた状態で F1 を押した場合、ユーザーが追加のフォームを 1 つだけ開くことを許可する制限が必要です。メッセージボックスが表示され、最初に 2 番目のフォームを閉じるように指示されます。
これが私がこれまでに持っているものです。
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
fOpen = true の場合、ユーザーが F1 を押すことを禁止するようなものでしょうか? よくわかりませんが、近いです。