Hiding/unhiding forms

  • Thread starter Thread starter FatMax
  • Start date Start date
F

FatMax

Access 97. I have two forms A and B which both contain a command
button that opens form C and hides A or B.

When I close C I'd like to return to A or B (whichever one I opened C
from).

I'd appreciate some clues :)

FatMax
 
Place a text box on form C to hold the name of the form that opened it:

DoCmd.OpenForm "C"
Forms!C!txtCallingForm = Me.Name
Me.Visible = False


Then in the Close event of form C:

If Not IsNull(Me.txtCallingForm) Then
Forms(Me.txtCallingForm).Visible = True
End If
 
FatMax, I'm assuming you have both forms open and that whichever form you
open formC from that you are hidding that form. After that, when you close
formC you want the one you hid to be shown.


Private Sub Form_Close()
On Error GoTo Err_Close

If IsLoaded("FormA") And Not Forms!FormA.Visible Then
Forms!FormA.Visible = True
Forms!FormA.SetFocus
ElseIf IsLoaded("FormB") And Not Forms!FormB.Visible Then
Forms!FormB.Visible = True
Forms!FormB.SetFocus
End If

Exit_Close:
Exit Sub

Err_Close:
MsgBox Err.Description & Err.Number
Resume Exit_Close
End Sub
***********************
Public Function IsLoaded(ByVal strFormName As String) As Integer
Const CLOSED = 0
Const DESIGN = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> CLOSED Then
IsLoaded = True
End If
End Function
 
Thanks for the advice. I only have A or B open at any one time so I
went with the idea from Allen Browne which worked a treat.

Mucho regards to both of you
FatMax
 
Back
Top