This procedure is used to search through a database of customers via first and last names. If the user leaves the txtSearchFirst or txtSearchLast fields empty, a msgbox is displayed and the search is cancelled. Why is the sub continuing to the next lines of code if it should be exiting the sub?
VB Code:
Private Sub cmdSearch_Click() If txtSearchFirst = "" Or txtSearchLast = "" Then MsgBox "Missing information for a valid search", vbCritical, "Warning!" Exit Sub End If adoSearch.Recordset.MoveFirst Do While Not adoSearch.Recordset.EOF If adoSearch.Recordset.Fields("First Name").Value = txtSearchFirst And _ adoSearch.Recordset.Fields("Last Name").Value = txtSearchLast Then MsgBox "Match Found!", vbInformation, "" fraResults.Visible = True imgResultsGirl.Visible = True imgWelcomeBack.Visible = True lblWelcomeName.Caption = txtResultFirst & " " & txtResultLast lblWelcomeName.Visible = True txtResultFirst = adoSearch.Recordset.Fields("First Name") txtResultLast = adoSearch.Recordset.Fields("Last Name") txtResultStreet = adoSearch.Recordset.Fields("Street") txtResultCity = adoSearch.Recordset.Fields("City") txtResultState = adoSearch.Recordset.Fields("State") txtResultZip = adoSearch.Recordset.Fields("ZipCode") txtResultPhone = adoSearch.Recordset.Fields("Phone") txtResultFax = adoSearch.Recordset.Fields("Fax") txtResultEmail = adoSearch.Recordset.Fields("Email") adoSearch.Recordset.MoveNext Loop Else MsgBox "No Match Found", vbInformation, "" Exit Sub End If End Sub




Reply With Quote