Wednesday, January 28, 2009

[vb6] Shuting down/Unload form in Form_Load event

You are doing some validation code in the Form_Load event. If that validation
code fails, then you do not want to show the form. If you call "Unload ME", you will get an error in the form that called ".Show" of the form loading, saying that the form is already unloaded.
  Private mbCancelForm As Boolean

Private Sub Form_Activate()
If mbCancelForm = True Then Unload Me
End Sub

Private Sub Form_Load()
mbCancelForm = False

If {SomeCondition} = True Then
MsgBox "False condition, unable to load the form", vbExclamation + vbOKOnly
mbCancelForm = True
End If
End Sub

No comments:

Post a Comment