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:
'check all txtboxes are filled in correctly If Len(txtName.Text) < 3 Then If MsgBox("Please enter a valid Drivers Name", vbOK, "Invalid driver name") = vbOK Then txtName.Text = "" txtName.SetFocus ErrorResult = "Yes" End If End If 'check agency name is correct format etc If Len(cmbAgencyName.Value) = 0 Then If MsgBox("Please enter a valid Agency Name", vbOK, "Invalid Agency Name") = vbOK Then cmbAgencyName.Value = "Pertemps" cmbAgencyName.SetFocus ErrorResult = "Yes" End If End If 'check there are the correct number of characters in date boxes If Len(txtAssessment.Text) <> 8 Then If MsgBox("Please enter a valid Assessment Date", vbOK, "Invalid Assessment Date") = vbOK Then txtAssessment.Text = Format(Date, "DD/MM/YY") txtAssessment.SetFocus ErrorResult = "Yes" End If End If If Len(txtLicense.Text) <> 8 Then If MsgBox("Please enter a valid License Checked Date", vbOK, "Invalid License Checked Date") = vbOK Then txtLicense.Text = Format(Date, "DD/MM/YY") txtLicense.SetFocus ErrorResult = "Yes" End If End If If Len(txtInduction.Text) <> 8 Then If MsgBox("Please enter a valid Induction Date", vbOK, "Invalid Induction Date") = vbOK Then txtInduction.Text = Format(Date, "DD/MM/YY") txtInduction.SetFocus ErrorResult = "Yes" End If End If 'if no errors go to next form If ErrorResult = "No" Then frmAgency.Hide frmTrainingClerical.Show End If




Reply With Quote