Check if a form is opened/close all forms

Doppenberg

Registered User.
Local time
Today, 00:17
Joined
May 25, 2000
Messages
25
Can anyone help me with some code to check whether a form is opened or not?
I want a button in my toolbar that returns to the main form and closes all other open forms (except the main form). I shouldn't matter whether there are two open form to be close or for example six open forms. They should all be closed.

Does anyone know how to create such a button?
 
Well you could use this function and pass the loop through all the forms in you database closing them if the fuction is true.

Function IsLoaded(aformname as string) as interger
on error goto IsLoaded_Err

dim x as string

x = Forms(aformname).name ' produces error 2450 if not loaded
IsLoaded = True
exit function

IsLoaded_Err:
if err = 2450 then
IsLoaded = False
else
msgbox ("An Error has occurred in Function IsLoaded:" & err & " " & error(err))
End if
Exit Function
End Function

Might be a bit of a pain depending how large you db is though. Hope it helps

Mitch.
 
Thanks for your help Mitch, I think this is
a possible solution.
The only problem is that there are about 40 forms in the DB.
Is there a way to loop through them from 1 to 40 or do I have to call the function 40 times and type the 40 form-names in VB?
This give problems when a new form is added later, because you must change the code then.

Greetings Tim.
 
You would have to type the form names in vb, which i agree is a pain and would have to modified if a new forms was added
frown.gif
but i don't know of any other way of finding out what objects are loaded. If anyone knows i'd be just as interested as you.

Mitch.
 
This might help

Private Sub LoopThroughForms()

Dim dbContainer As Container
Dim conDocument As Document

For Each dbContainer In CurrentDb.Containers
If dbContainer.Name = "Forms" Then
For Each conDocument In dbContainer.Documents
'do what you want for each form
'such as running the suggested IsLoaded code
'passing in conDocument.Name
Next conDocument
End If
Next dbContainer

End Sub

You could obviously modify this to loop through any or all containers and get the documents
Matt

[This message has been edited by MattGilbert (edited 05-25-2000).]
 
Would it be easier to make and maintain if you created a macro with 40 Close actions? Using copy/paste creating it should be a sinch, and it would be easy to add/remove/rename a form to close. This may not be elegant, but it may be an easy solution.
 
Thank you Jaxbuilder, you just made my day !!!

You're code worked great. I just tested it in a function and all my forms closed except for my main form. I tried something with forms before but it didn't close all my form, just like you explained. (because of the indexnrs).

Thanks, Tim
 

Users who are viewing this thread

Back
Top Bottom