Results 1 to 6 of 6

Thread: [Resolved]Exit loop when first user input error is found

Hybrid View

  1. #1
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Exit loop when first user input error is found

    Actually I've just noticed something else.. for the MsgBox's you have If statements when there is no need (as there is only one possible return value), you could have them like this:
    VB Code:
    1. If Len(txtName.Text) < 3 Then
    2.            MsgBox "Please enter a valid Drivers Name", vbOK, "Invalid driver name"
    3.            txtName.Text = ""
    4.            txtName.SetFocus
    5.            ErrorResult = "Yes"
    6.         End If
    ..which makes an alternative option spring to mind - you could use ElseIf, eg:
    VB Code:
    1. If Len(txtName.Text) < 3 Then
    2.            MsgBox "Please enter a valid Drivers Name", vbOK, "Invalid driver name"
    3. ...
    4.            ErrorResult = "Yes"
    5.  
    6.         'check agency name is correct format etc
    7.         ElseIf Len(cmbAgencyName.Value) = 0 Then
    8.            MsgBox ...
    9. ...
    10. ...
    11. ...    
    12.         'if no errors go to next form
    13.         Else
    14.             frmAgency.Hide
    15.             frmTrainingClerical.Show
    16.         End If
    This would be tidier, avoid any issues like salvelinus was thinking of, and would probably eliminate the need for your ErrorResult variable.

  2. #2

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Exit loop when first user input error is found

    Thanks to both salvelinus and si_the_geek.

    I actually have changes this to the ElseIf already, but thanks for the help.

    I did do a year or two of programming a couple of years ago, self taught at home, but I am only just getting back into it again, and thats VBA.

    Its a shame how much I seem to have forgotten.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

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



Click Here to Expand Forum to Full Width