Close all forms but one

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!
 
K

Klatuu

Docmd.Close acForm, "frmDemographics", acSaveNo
Docmd.OpenForm "frmVisits"

Whenever you close a form, any unsaved data will be save before the form
actually closes.
 
T

Tara

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!
 
K

Klatuu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Open form issue 1
Requery Macro 7
Update a listbox in a tab on a form 3
docmd.close 2
Embedded Macros 1
Forms Add, Edit or View 9
Callback function 3
Make Switchboard the active window? 1

Top