How to know which button pressed when a form closes
Forgive me I am sure this is really easy, but I do not know VB at all, and I got stuck with a program.
I am showing a form by calling this...
Form1.Show 1
This opens another "window" which collects data from the user, then the user can either hit the OK or CANCEL button. How does the calling function know what button the user pressed?
I assume that you could do something like this...
ButtonPressed = Form1.Show 1
but you can not.
Can any one help me answer this easy question?
Thanks a lot, I appricate it.
Re: How to know which button pressed when a form closes
Re: How to know which button pressed when a form closes
Well it should be easy my friend, but I neither understood the question nor the reply post :D
Re: How to know which button pressed when a form closes
you need to wrap the opening and closing of the form in a Public function within it.
e.g. in Form1, I have:
Code:
Private lRet As Long
Public Function ShowForm() As Long
Me.Show vbModal
ShowForm = lRet
Unload Me
End Function
Private Sub Command1_Click()
lRet = 1
Me.Hide
End Sub
Private Sub Command2_Click()
lRet = 2
Me.Hide
End Sub
in the calling form I have:
Code:
Private Sub Command1_Click()
Debug.Print Form2.ShowForm
End Sub