Greetings, I have a spreadsheet where I track whether or not visitors have been authorized to enter our plant. I am using the following code in a userform to see if the person has been approved yet or not, and I am currently just searching by the last name. However (I guess it was only a matter of time) someone showed up today that had the same last name as someone else. So I would like to tweak the code to look for the last and the first name.
On the userform the textbox for this value is "FirstNameBox" and the value is passed to column B. But I am not sure what command to use - would this be "And If"? I took a couple of runs at it with no luck, so I thought before I waste any more time I should confirm what statement I should be using to begin with. I appreciate any assistance - thanks, Rick
On the userform the textbox for this value is "FirstNameBox" and the value is passed to column B. But I am not sure what command to use - would this be "And If"? I took a couple of runs at it with no luck, so I thought before I waste any more time I should confirm what statement I should be using to begin with. I appreciate any assistance - thanks, Rick
Code:
Sub CheckName_Click()
Dim Found As Range
Dim i As Long
Dim Lastrow As Long
'This string looks to see if the person is in the database yet.
If Me.LastNameBox.Value = "" Then
MsgBox "No last name was entered, please enter the last name and try again ", , "No Name Entered"
Else
If Me.LastNameBox.Value = "" Then
MsgBox "No last name was entered, please enter the last name and try again ", , "Add name and try again"
Else
Set Found = Sheets("Accepted Visitors").Range("A:A").Find(What:=Me.LastNameBox.Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Found Is Nothing Then
MsgBox "No match for " & FirstNameBox.Value & " " & Me.LastNameBox.Value & ", a EUC clearance must be obtained.", , "No Match Found"
Else
MsgBox FirstNameBox.Value & " " & Me.LastNameBox.Value & " has obtained a EUC clearance, no further actions are necessary.", , "Match Found"
Exit Sub
End If
End If
End If
End Sub