Results 1 to 6 of 6

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

Threaded View

  1. #1

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

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

    I have the following code and I need to exit the checking if an error is found otherwise the user could have numerous msgboxs poping up one after another.
    I am not too sure how to do this.
    I have tried Do While, but either I got it wrong or this is not the correct way

    VB Code:
    1. 'check all txtboxes are filled in correctly
    2.         If Len(txtName.Text) < 3 Then
    3.            If MsgBox("Please enter a valid Drivers Name", vbOK, "Invalid driver name") = vbOK Then
    4.                 txtName.Text = ""
    5.                 txtName.SetFocus
    6.                 ErrorResult = "Yes"
    7.             End If
    8.         End If
    9.        
    10.         'check agency name is correct format etc
    11.         If Len(cmbAgencyName.Value) = 0 Then
    12.             If MsgBox("Please enter a valid Agency Name", vbOK, "Invalid Agency Name") = vbOK Then
    13.                 cmbAgencyName.Value = "Pertemps"
    14.                 cmbAgencyName.SetFocus
    15.                 ErrorResult = "Yes"
    16.            End If
    17.         End If
    18.        
    19.         'check there are the correct number of characters in date boxes
    20.         If Len(txtAssessment.Text) <> 8 Then
    21.             If MsgBox("Please enter a valid Assessment Date", vbOK, "Invalid Assessment Date") = vbOK Then
    22.                 txtAssessment.Text = Format(Date, "DD/MM/YY")
    23.                 txtAssessment.SetFocus
    24.                 ErrorResult = "Yes"
    25.            End If
    26.         End If
    27.        
    28.         If Len(txtLicense.Text) <> 8 Then
    29.             If MsgBox("Please enter a valid License Checked Date", vbOK, "Invalid License Checked Date") = vbOK Then
    30.                 txtLicense.Text = Format(Date, "DD/MM/YY")
    31.                 txtLicense.SetFocus
    32.                 ErrorResult = "Yes"
    33.            End If
    34.         End If
    35.        
    36.         If Len(txtInduction.Text) <> 8 Then
    37.             If MsgBox("Please enter a valid Induction Date", vbOK, "Invalid Induction Date") = vbOK Then
    38.                 txtInduction.Text = Format(Date, "DD/MM/YY")
    39.                 txtInduction.SetFocus
    40.                 ErrorResult = "Yes"
    41.            End If
    42.         End If
    43.    
    44.         'if no errors go to next form
    45.         If ErrorResult = "No" Then
    46.             frmAgency.Hide
    47.             frmTrainingClerical.Show
    48.         End If
    Last edited by aikidokid; Jan 28th, 2007 at 02:06 AM. Reason: Resolved
    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