automaticly closing forms

inbal

Registered User.
Local time
Today, 13:36
Joined
Feb 8, 2009
Messages
48
in my project there are a lot of forms/
when I open a form I want the rest of the open forms to close (to prevent too meny forms to be open at once)
how can i do it?
 
Are you saying anytime you open any form you want the currently open form to close? This is a bit of overkill, as it's designed to close all other forms except the calling form, but it'll work with only one other form open.

In a standard module (not the form's module) place this code:

Code:
Public Function CloseAllOtherForms(CurrForm)

 Do
  
  FormCnt = FormCnt + 1
 
  For Each frm In Application.Forms
   If frm.Name = CurrForm Then
    'Do nothing to calling form
   Else
    DoCmd.Close acForm, frm.Name
   End If
   Next frm
          
 Loop Until Application.Forms.Count <= 1

End Function

Save the Module. If it's a new Module, be sure to name it anything except "CloseAllOtherForms"! Naming a Module and a Function it contains the same thing confuses the Access Gnomes, and it won't work!

Now, in each form where you want all other open forms to be closed, place this code

Code:
Private Sub Form_Load()
 CloseAllOtherForms (Me.Name)
End Sub
 
i get an error....
FormCnt = FormCnt + 1
it tells me cant find project or library..
what should i do?
 
Add a line
Code:
Dim FormCnt As Integer
to your code at the top just below the
Public Function CloseAllOtherForms(CurrForm)
line
 
actually, after looking at the code, I don't think you need that line:

FormCnt = FormCnt + 1

at all anyway. Nowhere is FormCnt being used.
 
I'm sorry! :eek: Bob's correct, I was pulling this code from a more complicated hack and forgot to delete the offending line. Just delete it!
 
hi
thanks for the help but now it tells me
For Each frm In Application.Forms
cant find project or library...
 

Users who are viewing this thread

Back
Top Bottom