Check if All Forms are closed

Appreciate all your help!!!
 
PMFJI, Isn't there an End If missing for openFrm?

Okay, figured my stupidity, :banghead: try this.

Code:
Private Sub Command98_Click()
    Dim objAccObj As AccessObject
    Dim objProj As Object, openFrm As Boolean
    openFrm = True

    Set objProj = Application.CurrentProject
    For Each objAccObj In objProj.AllForms
        If objAccObj.IsLoaded() And objAccObj.Name <> Me.Name And objAccObj.Name <> "frmMainForm" Then
            openFrm = False
            Exit For
        End If
    Next objAccObj
    
    If openFrm Then _ 
        DoCmd.OpenForm "frmMainForm"
        
    DoCmd.Close acForm, "frmCandidates", acSaveYes
End Sub
 
Rather than looping through all forms in the database, you could use the Forms.Count property. If no forms are open, this returns zero. If you want to check the names of open forms including hidden one, loop between 1 and Forms.Count to check the names of open forms. If you're going to be closing forms in the loop, loop descending.
 
PMFJI, Isn't there an End If missing for openFrm?
No problem, yes it is missing an End If, but that will not cause any problem here because I have used a single line If statement, (with a line break _) which does not need an End If to terminate the If.

Rather than looping through all forms in the database, you could use the Forms.Count property. If no forms are open, this returns zero. If you want to check the names of open forms including hidden one, loop between 1 and Forms.Count to check the names of open forms. If you're going to be closing forms in the loop, loop descending.
Very good suggestion +1
 
No problem, yes it is missing an End If, but that will not cause any problem here because I have used a single line If statement, (with a line break _) which does not need an End If to terminate the If.

Now see, I did not know that. I'm glad I plucked up the courage to ask now. :D
 

Users who are viewing this thread

Back
Top Bottom