在主窗体的unload 事件中写 Private Sub Form_Unload(Cancel As Integer) Dim x as form for each x in forms unload x next End Sub 不行吗?
'卸载所有窗体(除一个窗体之外,一般为主窗体) Public Function sfFormsUnload(ByRef frm As Variant) As String Dim i As Integer For i = Forms.Count - 1 To 0 Step -1 If UCase$(Forms(i).Name) <> UCase$(frm.Name) Then Unload Forms(i) End If Next sfFormsUnload = "" End Function
dim x as form
for each x in forms
if x.name ="XXX"then ……
next
Private Sub Form_Unload(Cancel As Integer)
Dim x as form
for each x in forms
unload x
next
End Sub
不行吗?
Public Function sfFormsUnload(ByRef frm As Variant) As String
Dim i As Integer
For i = Forms.Count - 1 To 0 Step -1
If UCase$(Forms(i).Name) <> UCase$(frm.Name) Then
Unload Forms(i)
End If
Next
sfFormsUnload = ""
End Function
我有一个笨办法,用全局变量,打开窗体时为真。unload时,判断全局变量是否为真