Close all forms but one

  • Thread starter Thread starter Tara
  • Start date Start date
T

Tara

I need to find a way to keep my main form (frmIntake) open when another form
is opened and have any form that is currently open to close and save data.
For example, I need frmIntake to be open when frmDemographics is open. When
I click the command button to open frmVisits, I need frmIntake to remain
open, but I need frmDemographics to save data and close. How can I
accomplish that?

Thanks for any help!
 
Docmd.Close acForm, "frmDemographics", acSaveNo
Docmd.OpenForm "frmVisits"

Whenever you close a form, any unsaved data will be save before the form
actually closes.
 
Thanks Klatuu, but actually, I was hoping for a more generic way so that I
don't have to account for whatever specific form may be open at the time.
frmIntake actually contains command buttons that allow the user access to any
other form in the db. That's one reason I need to keep that form open. But
coding each button to account for the other 10 forms would be cumbersome. Do
you have any other suggestions?

Thanks!
 
Okay. Here is a sub that will close all open forms except frmIntake:

Public Sub CloseAllForms()
Dim frms As AllForms
Dim lngX As Long

Set frms = CurrentProject.AllForms
For lngX = 0 To frms.Count - 1
If frms(lngX).Name <> "frmInTake" Then
If frms(lngX).IsLoaded Then
DoCmd.Close acForm, frms(lngX).Name, acSaveNo
End If
End If
Next lngX
Set frms = Nothing
End Sub
 
Back
Top