Closing forms in background

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My database opens a form directly from another form but the original form
stays open. What is the easiest way to shut the original form automatically
when shutting the current form? There are other forms open at the same time
but I wan't them to stay.
 
My database opens a form directly from another form but the original form
stays open. What is the easiest way to shut the original form automatically
when shutting the current form? There are other forms open at the same time
but I wan't them to stay.

You want both form1 and form2 open until you close form2.

Code the close event of form2:

DoCmd.Close acForm, "Form1"
 
Thanks. I knew it would be simple!

fredg said:
You want both form1 and form2 open until you close form2.

Code the close event of form2:

DoCmd.Close acForm, "Form1"
 
Forgot something else regarding this question. How do you check if the form
is open before attempting to close it. Sometimes, the current form is opened
directly rather than from the other form so trying to close the other form
creates an error.
 
Forgot something else regarding this question. How do you check if the form
is open before attempting to close it. Sometimes, the current form is opened
directly rather than from the other form so trying to close the other form
creates an error.

What version of Access?
Access 2000 or newer?

If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) into a module:

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Then code some event:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if
 
Back
Top