Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test if a form is already loaded

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I'm looking for a way to test if a user form already loaded. Browsing the web I found examples such as

Code:
if frm[FormName].visible = true then
     ...stuff...
end if

But is there a way to determine if the form is loaded, even is it is not visible?

Is this a possible place to apply creating my own events with class subs? I've been learning about class subs recently, but I haven't gotten into that aspect of them. I've only heard you can do it.

-JTBorton
If it isn't broken, it doesn't have enough parts yet.
 
You can loop through the Forms collection to see if a form is loaded. Something like:
Code:
Dim frm As Form

For Each frm In Forms
    Debug.Print frm.Name
Next frm
Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
If CurrentProject.AllForms("yourForm").IsLoaded Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My reply was for an AccessForm.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
HarleyQuinn

What reference library has the Form object? I have MS Forms 2.0 and I tagged VBA Extensibility 5.3, but it is still not coming up in the intellisense.

I tried to bypass the issue by declaring Frm as an object, but VBA is not recognizing the Forms collection either. I'm using Excel 2003 prof.

Compile error:
Variable not defined


Code:
Dim objForm As Object

    For Each objForm In [highlight]Forms[/highlight]
        Debug.Print objForm.Name
    Next objForm

-JTBorton
If it isn't broken, it doesn't have enough parts yet.
 
Sorry JT, I should have said the code (similar to PHV's) was for Access.

You could replicate the functionality by creating your own
Public collection and adding/removing when forms are loaded unloaded and that could work in the same way.

Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Code:
Dim objForm As Object
For Each objForm In UserForms
  Debug.Print objForm.Name & " IS LOADED"
Next objForm

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top