How to close a form from another

  • Thread starter Thread starter Emilio
  • Start date Start date
E

Emilio

Hi,

I am a newbie and need to be able to close a form when
opening another one, but because I am using (code
provided by someone who helped me before):

-------------------------------------
Dim mbooOKToClose As Boolean
-------------------------------------
Private Sub Form_Unload(Cancel As Integer)
If mbooOKToClose Then
Cancel = False
Else
Cancel = True
End If
End Sub
--------------------------------------
Private Sub Exit_Calendar_Click()
mbooOKToClose = True
DoCmd.Close
End Sub
---------------------------------------

I have 1 form ("frmCheckOrders")
that in order to open has to close "frmJobEntry" first.

I tried different ways to force:

Close_Form_Click (in "frmJobEntry")
to work from the
Private Sub Form_Open in "frmCheckOrders"
but I can't get it to work

The other way I was trying is in Lost Focus
in "frmJobEntry":

If "frmCheckOrders" is open then ......... or
If Not IsNUll "frmCheckOrders".field then........

but with my limited knowledge, can't figure it out.

Any help is appreciated,
Emilio
 
Hello,

I would try something like this:

In the on open command on the frmCheckOrders form try this:

frmJobEntry.Close

then when the form Check Orders opens it should close the
other form.

I am not too sure about teh code off the top of my head
but if you have any problems just post back and I will
have a look into it ok? Unless someone else posts and
corrects my code but that would be the simplist way of
doing things.

HTH

James
 
Assuming that the form you want to close is named frmMyForm then from
anywhere within your app you can write:

DoCmd.Close acForm, "frmMyForm"
 
Thanks for your response but the problemis:

Dim mbooOKToClose As Boolean

does not allow the form to close without:
mbooOKToClose = True


Thanks again,
Emilio
 
Thanks for your response but the problemis:

Dim mbooOKToClose As Boolean

does not allow the form to close without:
mbooOKToClose = True


Thanks again,
Emilio
 
Emilio said:
I am a newbie and need to be able to close a form when
opening another one, but because I am using (code
provided by someone who helped me before):

-------------------------------------
Dim mbooOKToClose As Boolean
-------------------------------------
Private Sub Form_Unload(Cancel As Integer)
If mbooOKToClose Then
Cancel = False
Else
Cancel = True
End If
End Sub
--------------------------------------
Private Sub Exit_Calendar_Click()
mbooOKToClose = True
DoCmd.Close
End Sub


Change the mbooOKToClose variable's declaration to Public so
it can be set from outside frmJobEntry's module.

Public mbooOKToClose As Boolean

Then in the frmCheckOrders form, reference the first form to
reset the variable:

Forms("frmJobEntry").mbooOKToClose = True
DoCmd.Close acForm, "frmJobEntry", acSaveNo
 
Thanks a lot, it works

Emilio


-----Original Message-----



Change the mbooOKToClose variable's declaration to Public so
it can be set from outside frmJobEntry's module.

Public mbooOKToClose As Boolean

Then in the frmCheckOrders form, reference the first form to
reset the variable:

Forms("frmJobEntry").mbooOKToClose = True
DoCmd.Close acForm, "frmJobEntry", acSaveNo
 
Back
Top