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

How to test to see if a form is open 3

Status
Not open for further replies.

Modex

Programmer
Sep 15, 2002
155
GB
Hi All,

I wonder if someone could help me on this, I have had a real hard search through Tek-Tips but I probably am not using the right words for the search criteria.

Basically I have a number of forms that a user can go in and out of depending on what they are doing, but on some occasions when a form closes I need to test to see if another form is open but hidden, so that I can say something along the lines of

If formx is open then just close me (Formx will then Display by default)
If formx is not open then openformx

So basically I need some way of testing if formx is open or not.

Any help would be gratefully received

Many thanks

ModeX
 
Hi

Several ways to do this, but one way is:

Public Function IsLoaded(MyFormName As Variant) As Boolean
Dim i As Integer
IsLoaded = False
For i = 0 To Forms.Count - 1
If Forms(i).Name = MyFormName Then
IsLoaded = True
i = Forms.Count + 1
End If
Next

End Function

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

more than one method but one is:

Public Function IsLoaded(MyFormName As Variant) As Boolean
Dim i As Integer
IsLoaded = False
For i = 0 To Forms.Count - 1
If Forms(i).Name = MyFormName Then
IsLoaded = True
i = Forms.Count + 1
End If
Next

End Function

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi Ken,

Many thanks for the really quick response.

I am so sorry to appear so naïve in this, but haven’t been able to use access for a few months now and am a little rusty.

I may have got this completely wrong here, if I am, could you please point me in the right way of doing things.

Looking at the code you supplied

I placed the function into a module replacing the “MyFormName” with the name of my form “Welcome” so the code now looks like this.

Public Function IsLoaded(Welcome As Variant) As Boolean
Dim i As Integer
IsLoaded = False
For i = 0 To Forms.Count - 1
If Forms(i).Name = welcome Then
IsLoaded = True
i = Forms.Count + 1
End If
Next

End Function

I then try to call this function on its own, from a button and get “argument not Optional” I have also tried placing the function in the Form itself and get the same error.

I then need to test the results, I presume once its working I would perform some action like

If isloaded = 0 then
Do something
Else
Do something else
End if

Many thanks Ken

Nigel
 
Using the code as I originally gave it to you, in a module as you said, the code in the button would be:

If isloaded("Welcome") then
Do something
Else
Do something else
End if


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Here's another way:

Msgbox CurrentProject.AllForms("YourFormName").IsLoaded
 
Hi

Yes I have come across that, but in Access2000 if gives an error 2467, in which version did it become available?

The IsLoaded() function works in all commonly used versions (ie A97, A2000, A2003)

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
It became available in Access2000. It works ok for me. Strange you're getting that error.
 
Thanks Ken and Thanks FancyPrairie.

Much appreciated, yet another Hurdle overcome, I dare say there will be many more.

Thanks very much guys.

Cheers

Nigel
(Modex)












 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top