Closing Forms as others open

Webskater

Registered User.
Local time
Today, 12:30
Joined
Aug 29, 2006
Messages
14
To try to keep a sane user interface I would like to close forms as another form opens.

If I put a Command button on FormA that opens FormB and it is set to find a record on FormB ... how can I close FormA when FormB opens.

I tried putting DoCmd.Close either before and after the code that opens FormB and ...

If I put it before the code - it just closes FormA without opening FormB ... if I put it after the code, if opens FormB and closes it.

Is there a way of saying on a form 'close the form that just opened me'? (like in javascript where you can reference the form with window.opener)

Thanks for any help.
 
re:

Hi,
try this instead:

DoCmd.Close acForm, Me.Name

HTH
Good luck
 
If all else fails what you could do is put an event procedure against the On Got Fucus on the first field of form be as
Docmd.close acform."FormB"

L
 
What I do is make the calling form visible state = False. When I close the form that has been called I then change the visible state of the original from to True. This saves time opening and closing forms unless of course you need to run code under the On Open event of the form.

See the following code which runs on the click of a button on a menu form

Code:
Private Sub butFuel_Click()
On Error GoTo Err_butFuel_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    Me.Visible = False
    stDocName = "frmFuel"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_butFuel_Click:
    Exit Sub

Err_butFuel_Click:
    MsgBox Err.Description
    Resume Exit_butFuel_Click
    
End Sub

The following code runs when I close the form that is opened in the above code

Code:
Private Sub Form_Close()
    Call OpenMainMenu
End Sub

The procedure "OpenMainMenu" checks (by running a function) if the Main Menu form is actually open before chainging the visible state to True. If not then it will open it.

The procedure and function are as follows:

Code:
Public Sub OpenMainMenu()
    If IsLoaded("frmMainMenu") Then
        Forms!frmmainmenu.Visible = True
    Else
        DoCmd.OpenForm "frmMainmenu"
        
    End If
End Sub

Code:
Public Function IsLoaded(ByVal strFormName As String) As Boolean
 ' 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


HTH
 

Users who are viewing this thread

Back
Top Bottom