NNOAM1
asked on
know if an Access form is loaded
I have always seen this code for detecting if a form is loaded:
Dim blMyFormLoaded As Boolean
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = True And obj.Name = "[put_here_the_desired_for m-name]" Then
blMyFormLoaded = True
Exit For
End If
Next obj
But I've come up with this Idea:
Dim blMyFormLoaded As Boolean
Dim f As Form
For Each f In Application.Forms
If f.Name = "[put_here_the_desired_for m-name]" And f.CurrentView<>0 then
blMyFormLoaded = True
Exit For
End If
Next
Doesn't it seem that the second is better? The Forms collection contains only open forms, while the AllForms collection contains all of them. Consider the fact that my app has got 666 forms.
Dim blMyFormLoaded As Boolean
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = True And obj.Name = "[put_here_the_desired_for
blMyFormLoaded = True
Exit For
End If
Next obj
But I've come up with this Idea:
Dim blMyFormLoaded As Boolean
Dim f As Form
For Each f In Application.Forms
If f.Name = "[put_here_the_desired_for
blMyFormLoaded = True
Exit For
End If
Next
Doesn't it seem that the second is better? The Forms collection contains only open forms, while the AllForms collection contains all of them. Consider the fact that my app has got 666 forms.
ASKER
OK, let's remove the: "And f.CurrentView<>0". Are both methods OK with you?
Yes, but I think I would do:
/gustav
Dim blMyFormLoaded As Boolean
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = True Then
If obj.Name = "[put_here_the_desired_form-name]" Then
blMyFormLoaded = True
Exit For
End If
End If
Next obj
Dim blMyFormLoaded As Boolean
Dim f As Form
For Each f In Application.Forms
If f.Name = "[put_here_the_desired_form-name]" Then
If f.CurrentView <> 0 Then
blMyFormLoaded = True
Exit For
End If
End If
Next
/gustav
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's the thing I was looking for! Thank you.
Under normal use most apps have zero forms open in designview.
/gustav