Code for verifying if a form is loaded

JimMiller

Registered User.
Local time
Today, 01:02
Joined
Oct 22, 2001
Messages
18
I am looking for the code when given a form name will return if the form is loaded or not loaded in the system. Does anyone know the syntax or other ways to achieve my objective?

Thanks!
 
Never mind. I figured it out. Below is a way to loop through all the loaded forms...


Sub CloseForms()
Dim i As Integer
For i = (Forms.Count - 1) To 0 Step -1
If Forms(i).Name <> "MainForm" Then
DoCmd.Close acForm, Forms(i).Name
End If
Next i
End Sub
Loop through the open forms (a form will be in the FORMS collection only if it is open). Change "MainForm" to the name you do not want to close. The loop must run in reverse since the form index numbers change when a form is closed (that is, if you close form(2), then all forms with a higher index are renumbered). If you try this code with the loop index running up from 0 it won't close all the forms.
 

Users who are viewing this thread

Back
Top Bottom