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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if form is loaded

Status
Not open for further replies.

jbsys

Programmer
May 6, 2005
51
0
0
CA
Is there an easy way to do this?
 
Iterate the forms collection
Code:
Dim f As Form
For Each f In Forms
   If f.Name = "Form1" then 
      MsgBox "Form1 is Loaded"
      Exit For
   End If
Next
 
Is the form loaded" as in "is the application active"?

How about App.PrevInstance?
.
 
GhostWolf,
App.PrevInstance is not about the forms. Golom showed how to do this.
vladk

 
Golom, that looks awfully famillar. Why not just provide a link to my code instead? :(

-David
2006 Microsoft Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
David, yeah! Looks like some of my code too in e.g thread222-795815
Or vb5prgrmr's in e.g. thread222-641181
Or johnwm's in e.g. thread222-736948
And ...
(all of which predate your membership of this site)

My point is that there's really only about one way to enumerate through the forms collection, so all such solutions will look pretty similar ...
 
dglienna and strongm

Sorry guys. I didn't really plagerize your code. That's just the standard "how to enumerate a collection" code that I use all the time and apparently so does everyone else.

Guess I could have said
Code:
On Error Resume Next
Dim f As Form
Set f = Forms("Form1")
if Err.Number = 0 Then MsgBox "Form1 is loaded"

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
> I didn't really plagerize your code. That's just the standard "how to enumerate a collection" code

I know, that was precisely the point I was trying to make. Irony doesn't travel well ...
 
Sorry strongm. Didn't really mean to include you in that.

... and yes, I did get the irony.

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
Hmmm... GMTA I guess, all calling the forms object the same think, which is the simplest. f!

I can't say that I invented the technique, and wasn't complaining, per se. Just making an observation.

-David
2006 Microsoft Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
One thing I do is add a boolean for the form in a module.

In the module
Global bForm1Open as boolean

In the form open event

bForm1Open = true

in the form close
bForm1Open = false

Then test for the boolean value
 
Um ... OK ... a few points though:

1) A loaded form and an open form are two different things (but, yep, you could change it you bForm1Load and oput it in the load event)
2) Global is obsolete; you should probably use Public instead
3) Seems like a lot more effort (because, presumably, you also have to unset the boolean when the form closes) for very little gain against the enumeration method. I guess it has the advantage of looking simpler

 
For completeness's sake, dg, I wonder if you might provide the link to your thread wherein golom is said to have cut and pasted your code? If one of the frequent examples I provide off the cuff on this subject happens to exactly reproduce yours, I'd like to make sure that I reference your link.

TIA,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top