Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Location
    All over, Now in Missouri
    Posts
    78

    Unanswered: How to use Exit Sub

    I was using "Exit Sub" to return the user to a Text Box if the test failed. I read on FMSInc that you should not use exit sub, rather use Boolean, and let the code finish.

    Here is what I do:

    If IsNull(txtBox) or me.txtBox = "" then
    MsgBox "Box Empty!", vbOKOnly, "My Message!"
    me.txtBox.SetFocus
    Exit Sub
    EndIf

    Could be many lines of code following test


    Is this proper?
    We tend to look at Linear paths which can lead us to a path of resistance!

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    630
    Provided Answers: 35
    sure, you can put as many EXIT SUBs that you need.
    you are only allowed 1 : END SUB (it defines the sub)

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,764
    Provided Answers: 19
    If the user simply ignores the Control, never entering it, your validation code will be ignored! Validation, checking whether a Control is populated or not, has to be done in the Form_BeforeUpdate event, just prior to the Record being saved.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •