Reading cancel from a form

J

John

Hi

My main form opens another form that has a set of OK and cancel buttons. How
can I find out in the main form if user closed the child form using cancel
button?

Thanks

Regards
 
P

Pieter Wijnen

One Way is not to actually close the seccond Form, just set it's visible
property to False & Have a Unbound TextBox/CheckBox Updated, Depending on
which button was pressed (CloseChoice). If You Open Form2 as a Modal form
(AcDialog) & Don't have a Timer Event on it
The Logic can be placed on Form2, as Code for other Forms gets suspended

HtH

Pieter


In Form #1

Private Sub btnForm2_Click()
Dim F As Form
DoCmd.OpenForm "Form2" '.........
Set F = Forms(Form2)
While F.Visible=True
VBA.DoEvents
Wend
Debug.Print F.CloseChoice.Value
Access.DoCmd.Close acForm, "Form2"
End Sub
 
M

Marshall Barton

That's good, but when Form2 is opened in dialog mode, there
is no need for the time wasting loop:

Private Sub btnForm2_Click()
DoCmd.OpenForm "Form2", WindowMode:=acDialog
Debug.Print Forms!Form2.CloseChoice
Access.DoCmd.Close acForm, "Form2"
End Sub
 
P

Pieter Wijnen

I thought I said so <g>

Pieter

"Pieter Wijnen"
One Way is not to actually close the seccond Form, just set it's visible
property to False & Have a Unbound TextBox/CheckBox Updated, Depending on
which button was pressed (CloseChoice). If You Open Form2 as a Modal form
(AcDialog) & Don't have a Timer Event on it
The Logic can be placed on Form2, as Code for other Forms gets suspended

HtH

Pieter


In Form #1

Private Sub btnForm2_Click()
Dim F As Form
DoCmd.OpenForm "Form2" '.........
Set F = Forms(Form2)
While F.Visible=True
VBA.DoEvents
Wend
Debug.Print F.CloseChoice.Value
Access.DoCmd.Close acForm, "Form2"
End Sub
 
G

Guest

If the key here is you want to know how the other form was closed, you will
need a control on the first form (which can be hidden) for the other form to
insert a value indicating how it was closed. One thing you will need to be
aware of is when the user closes the form using the form's close button. In
this case, you can pass the value to the first form in the Unload event of
the other form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top