Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Apr 16, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Use Custom Form Properties

You can easily find out whether your user clicked on OK or on Cancel on a modal dialog. This example also prevents the user from unloading the form, and thereby prevents you from inadvertently reloading the form when you reference the properties of controls on the form:
Option Explicit

Private mUserHitOK As Boolean

Public Property Get UserHitOK() As Boolean
	UserHitOK = mUserHitOK
End Property

Private Sub cmdCancel_Click()
	mUserHitOK = False
	Call Hide
End Sub

Private Sub cmdOK_Click()
	mUserHitOK = True
	Call Hide
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode _
	As Integer)
	If UnloadMode = vbFormControlMenu Then
		Cancel = True
		cmdCancel.Value = True
	End If
End Sub
You only need this code to check the user action:
Call frmModalDialog.Show(vbModal)
If frmModalDialog.UserHitOK Then
	' Do Something Here
	' Do Something Else Here
End If
Call Unload(frmModalDialog)
Set frmModalDialog = Nothing
Thomas Weiss
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date