title: Stop form from closing conditionally
body: <p>My problem is that I don't know a suitable command to stop my code from running. If I use a return statement, like below, the code in the subroutine btnClose will keep running causing the program to close on an error. The form must not close if an error on saving occurs.</p>
  
  <pre><code>Private Sub Save_Customer()
     If txtName.text = "" then
         msgbox("Error")
         return
     End If
  End sub
  
  Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
      save_Customer()
      Me.Close()
  End Sub
  </code></pre>