While Not fMainForm.ActiveForm Is Nothing
            Unload fMainForm.ActiveForm
        Wend

解决方案 »

  1.   

    '卸载所有窗体(除一个窗体之外,一般为主窗体)
    Public Function sfFormsUnload(ByRef frm As Variant) As String
    On Error GoTo ErrTrap
        Dim i As Integer
        If Not TypeOf frm Is Form Then
            sfFormsUnload = MErrCtrl.dfSemCreate("sfFormsUnload", -1, "Invalid argument")
        
        End If
        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 = ""
        Exit Function
        
    ErrTrap:
        sfFormsUnload = MErrCtrl.dfSemCreate("sfFormsUnload", Err.Number, Err.Description)
        On Error GoTo 0
    End Function
    '创建一个安全错误消息
    Public Function dfSemCreate(ByVal strCallingRoutine As Variant, _
                                ByVal lngErrorCode As Variant, _
                                ByVal strErrorDetails As Variant, _
                                Optional ByVal strPrevSEM As Variant = "") As String
    On Error GoTo ErrTrap
        strCallingRoutine = MTpToTp.dfVntToTrimStr(strCallingRoutine)
        lngErrorCode = MTpToTp.dfVntToLng(lngErrorCode)
        strErrorDetails = MTpToTp.dfVntToTrimStr(strErrorDetails)
        strPrevSEM = MTpToTp.dfVntToTrimStr(strPrevSEM)
        
        dfSemCreate = strPrevSEM & strCallingRoutine & vbTab & _
                      CStr(lngErrorCode) & vbTab & strErrorDetails & vbLf
        Exit Function
    ErrTrap:
        dfSemCreate = "dfSemCreate" & vbTab & _
                     CStr(Err.Number) & vbTab & _
                     "Could not create Safe Error Message." & vbLf
        On Error GoTo 0
    End Function
      

  2.   

    sunbf(大富) ,: x_bigman(草胚子) ,谢谢你们!