S
streamaxi
I have an userform (Name=MyForm) with lots of controls. Two of them are
Employee ID (Name=aEmpID) and Employee (Name=aName).
I have tried lot of things in the Private Sub aEmpID_AfterUpdate() but
not successful. What I want is, if I enter the employee ID, it should
search that ID in the worksheet named "DB" in column "A" and take the
corresponding Employee name from column "B" and populate in aName.value
control.
Private Sub aEmpID_AfterUpdate()
Dim rCount As Integer
Dim lRow As Integer
rCount = 1
lRow = Sheets("DB").Range("A65536").End(xlUp).Row
If Len(aEmpID.Value) <> 5 Or Not IsNumeric(aEmpID.Value) Then MsgBox
"Incorrect Employee ID"
For i = 1 To lRow
If Sheets("DB").Range("A & rCount & ").Value = aEmpID.Value Then
aName.Value = Sheets("DB").Range("A & lRow & ").Offset(0,
1).Value
End If
rCount = rCount + 1
Next i
End Sub
I am getting the following error in the line If Sheets("DB").Range("A &
rCount & ").Value = aEmpID.Value Then
Run-time error '1004':
Application-defined or object-defined error
Please help.
Employee ID (Name=aEmpID) and Employee (Name=aName).
I have tried lot of things in the Private Sub aEmpID_AfterUpdate() but
not successful. What I want is, if I enter the employee ID, it should
search that ID in the worksheet named "DB" in column "A" and take the
corresponding Employee name from column "B" and populate in aName.value
control.
Private Sub aEmpID_AfterUpdate()
Dim rCount As Integer
Dim lRow As Integer
rCount = 1
lRow = Sheets("DB").Range("A65536").End(xlUp).Row
If Len(aEmpID.Value) <> 5 Or Not IsNumeric(aEmpID.Value) Then MsgBox
"Incorrect Employee ID"
For i = 1 To lRow
If Sheets("DB").Range("A & rCount & ").Value = aEmpID.Value Then
aName.Value = Sheets("DB").Range("A & lRow & ").Offset(0,
1).Value
End If
rCount = rCount + 1
Next i
End Sub
I am getting the following error in the line If Sheets("DB").Range("A &
rCount & ").Value = aEmpID.Value Then
Run-time error '1004':
Application-defined or object-defined error
Please help.