Suppose that the form frmDialog is meant to be a custom dialog that is called from code. The form takes values (like a user name and a password) and returns them to the calling procedure. The problem is the calling procedure does not "wait" for the values returned from the form.
To stop execution of code while the frmDialog is visible, open frmDialog modally with the form:
Call frmDialog.Show(Modal:=vbModal, _
OwnerForm:=frmMain)
where frmMain is the Startup Object of the project. Now suppose that frmDialog has a Cancel button with the following Click Event:
Private Sub cmdCancel_Click()
CancelDialog = True
Me.Visible = False
End Sub
where CancelDialog is a Public Boolean of the frmDialog. Once frmDialog.Visible = False, the calling procedure (basCallingSub()) stops waiting. The following lines of code has the form:
If frmDialog.CancelDialog Then
'User clicked Cancel.
Call VB.Unload(frmDialog)
Set frmDialog = Nothing
GoTo basCallingSub_Exit
Else
'Get values from frmDialog.
With frmDialog
strUserName = .txtUserName.Text
strPassword = .txtPassword.Text
End With
Call VB.Unload(frmDialog)
Set frmDialog = Nothing
End If
where the Unload() Method of the VB Object removes the frmDialog UI from memory. Setting frmDialog = Nothing removes the frmDialog code from memory such that when it is called again, its variables wil be reinitialized.