[RESOLVED] Another VB Mystery??
Hi again. I have one form (form1) opening another form (form2) as a dialog box. The user may enter some data into form2, then will press either cmdOK or cmdCancel to finish.
I want form1 to be able to know which button the user pressed in form2. I tried it like this;
VB Code:
{form1}
load form2
form2.show
{form2}
Private Sub cmdCancel_Click()
Me.Visible = False
End Sub
{form1 again}
if form2.cmdCancel.value then
(disregard the operation because they pressed the cancel cmd button)
endif
In the form2 cmd_click sub, the cmdCancel property is TRUE after they press Cancel. But as I step thru the program, I notice that when it returns to form1, the cmdCancel value is set to FALSE.
Any ideas how form1 can read the values of the form2 command buttons?
Thanks again - Tom
Re: [RESOLVED] Another VB Mystery??
I didn't even know command buttons had a Value property.
Anyway, I suppose you are making a custom Messagebox or something, so here's how you'd do that, with parameters:
VB Code:
' In a module somewhere
Enum CustomMsgBoxResult
mbOK
mbCancel
End Enum
Function CustomMsgBox(ByRef pszData As String, ByRef pszCaption As String) As CustomMsgBoxResult
With <message box form>
.lblData = pszData
.Caption = pszCaption
.Show vbModal
CustomMsgBox = .Result
End With
End Function
VB Code:
' In the form
Private mResult As CustomMsgBoxResult
Property Get Result() As CustomMsgBoxResult
Result = mResult
End Property
Private Sub cmdOK_Click()
Result = mbOK
Me.Hide
End Sub
Private Sub cmdCancel_Click()
Result = mbCancel
Me.Hide
End Sub
HTH :)