Close all open objects

I must be really dense 'cause I can't get it to work.

aob = Nothing on the 1st pass, logic goes straight to Error from line 20

Code:
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Form_Unload
10  Dim aob As AccessObject
  
20  [B][COLOR=darkred]For Each aob In Forms[/COLOR][/B]                                ' Forms
30      If aob.IsLoaded Then
40          If aob.Name <> "frmMain" Then DoCmd.Close acForm, aob.Name, acSaveYes
50      End If
60  Next aob
  
70  For Each aob In Reports                              ' Reports
80      If aob.IsLoaded Then DoCmd.Close acReport, aob.Name, acSaveYes
90  Next aob
 
Exit_Form_Unload:
    DoCmd.SetWarnings True
    DoCmd.Hourglass False
    Exit Sub
Err_Form_Unload:
    ErrorLine = Erl
    ErrorNumber = Err.Number
    ErrorDescription = Err.Description
    ErrorForm = "frmMain"
    ErrorSourceType = "Sub"
    ErrorSourceName = "Form_Unload"
    Call gsubErrorHandler(ErrorLine, ErrorNumber, ErrorDescription, ErrorForm, _
                          ErrorSourceType, ErrorSourceName)
    Resume Exit_Form_Unload
End Sub

Robert
 
No IsLoaded test required in the Application collection since they are only in them when they are loaded.

Moreover IsLoaded is not a property of the members in those collections.
 
I must still be missing something.

aob=Nothing

Code:
10  Dim aob As AccessObject
 
20  [B][COLOR=darkred]For Each aob In Forms[/COLOR][/B]                                ' Forms
30      If aob.Name <> "frmMain" Then DoCmd.Close acForm, aob.Name, acSaveYes
40  Next aob
 
50  For Each aob In Reports                              ' Reports
60      DoCmd.Close acReport, aob.Name, acSaveYes
70  Next aob

Robert


EDIT: I was doing some random quesswork and used AS OBJECT. But it only closed 2 out of 4 forms, and it saw the Main form.
 

Users who are viewing this thread

Back
Top Bottom