Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

minimising form 1

Status
Not open for further replies.

hirenJ

Programmer
Dec 17, 2001
72
GB
Hi all,

I have a form1 that contains a button to open up form2.

When form2 opens, I would like form1 to minimise itself, I would then like to maximise form1 when form2 closes.

Is there a way to do this in code? Can the code be written so that form2 can be used independantly, without opening form1 if need be?

Thanks

Hiren

:eek:)
 
Here's one way that lets you use Form2 independently.

In Form1, the command button's Click event minimizes the form before opening Form2:
Code:
Private Sub Command1_Click()
    DoCmd.Minimize
    DoCmd.OpenForm "Form2"
End Sub
You also want Form1 to maximize itself when it gets the focus again. You do this in the Activate event:
Code:
Private Sub Form_Activate()
    DoCmd.Maximize
End Sub
When Form2 closes, it needs to check whether Form1 is open. If so, Form2 should activate it with OpenForm:
Code:
Private Sub Form_Close()
    If FormIsOpen("Form1") Then DoCmd.OpenForm "Form1"
End Sub
The FormIsOpen function can be coded in the form, or in a standard module so that it can be used from anywhere:
Code:
Public Function FormIsOpen(FormName As String) As Boolean
    Dim frm As Form
    
    On Error Resume Next
    Set frm = Forms(FormName)
    If Err = 0 Then FormIsOpen = True
    Set frm = Nothing
End Function
This isn't precisely what you asked for, in that Form1 maximizes itself any time it receives the focus, not just when Form2 closes, but I think that's what you were after. Rick Sprague
 
thats exactly what I needed!!

thankyou so much Rick :eek:)

Hj


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top