How to check whether there is any hidden forms

FuzMic

DataBase Tinker
Local time
Tomorrow, 05:07
Joined
Sep 13, 2006
Messages
744
Hi there again

I have form which can be toggled to visible or hidden. How to check it's status using VBA; what is the right collection to check this. I only know of Forms.Count or Reports.Count

I am sure it is just a step away, with a little help i will get there :(
 
Test form Visible property:

If Forms!formname.Visible Then


To test if a form is open at all, like:

If CurrentProject.AllForms("DataBituminous").IsLoaded Then
 
what is the right collection to check this
This implies you need to enumerate over forms because this
I have form
is a typo to me. The intent could be "I have a form" or "I have forms". If it's the latter, you probably need code that enumerates rather than just targeting one form by name. If that's the case, I/we should be able to come up with something quick and dirty.
 
Last edited by a moderator:
Yes, some confusion. "I have form" - is there an article 'a' missing? And "check its" - singular pronoun.
 
It is a form. Anyway thank you both of you. Sorry s or no s
 
I think you were being called out for it's (contraction for "it is") vs its. :)
It seems you don't need to iterate over multiple forms that might be open but since I hashed out a few lines of code for that I as well post it.

Code:
Sub WhoIsOpen()
Dim frm As Object
Dim frmName As String, strList As String

For Each frm In CurrentProject.AllForms
    frmName = frm.Name
    If frm.IsLoaded Then strList = strList & frmName & vbCrLf
Next
MsgBox strList

End Sub
Forgot to mention that a subform doesn't appear in such a list - just the parent form. I suspect that if you use either approach on a subform name, you won't get a hit.
 
Last edited by a moderator:
Why waste your time on allforms. That includes all forms in the project, loaded or not. Just use the "Forms" collection which would only include the loaded forms.
 
As far as I know, to do that requires that you know the form name or its index. The code I added was for when you don't know that or when there is more than one to be checked. Perhaps you missed the confusion part at the beginning where we questioned whether or not the task was to know if one form or several might be open. If so, I'd still do it that way rather than write a test for every one of them.

However, if you're saying you know a better way because you don't have to know the form index or name for enumerating the Forms collection, why don't you enlighten all of us instead? I'm always open to learning and would like to know how to do that and how much time can be saved.
 
As far as I know, to do that requires that you know the form name or its index. The code I added was for when you don't know that or when there is more than one to be checked. Perhaps you missed the confusion part at the beginning where we questioned whether or not the task was to know if one form or several might be open. If so, I'd still do it that way rather than write a test for every one of them.

However, if you're saying you know a better way because you don't have to know the form index or name for enumerating the Forms collection, why don't you enlighten all of us instead? I'm always open to learning and would like to know how to do that and how much time can be saved
Simply loop the "Forms" collection and check the visible property.
 
Guys and Gal, That's it, a big Thank you to all. Cheerio
 

Users who are viewing this thread

Back
Top Bottom