sn152
Member
I have a userform in which if I enter the ID it pulls the data related to that ID and displays it in the labels and texboxes in the userform. I am using the below code to do this.
Now the problem is this code works only when the ID is a number. But I have IDs which are text and numbers. For example - EMP1022. When I enter text it is showing an error. Could you please help me on this.
Now the problem is this code works only when the ID is a number. But I have IDs which are text and numbers. For example - EMP1022. When I enter text it is showing an error. Could you please help me on this.
Code:
Private Sub TextBox1_Change()
Dim m As Integer, id As Long
Dim l As Long, dictionary As Object, i, t As Long
Set dictionary = CreateObject("scripting.dictionary")
If IsNumeric(Me.TextBox1.Value) Then
Me.Label11.Caption = ""
Me.Label13.Caption = ""
Label3.Caption = ""
Label13.Caption = ""
Label5.Caption = ""
ListBox1.Clear
Label7.Caption = ""
Label9.Caption = ""
TextBox2.Value = ""
Label15.Caption = ""
Label17.Caption = ""
Label19.Caption = ""
Label26.Caption = ""
OptionButton3.Value = False
OptionButton2.Value = False
OptionButton1.Value = False
Me.ListBox1.Clear
For t = 3 To 34
On Error Resume Next
Me.Controls("TextBox" & t).Value = ""
Next t
On Error GoTo 0
id = Me.TextBox1.Value
m = 0
Do While Sheet3.Cells(m + 1, 1) <> ""
If Sheet3.Cells(m + 1, 1).Value = id Then
Me.Label3.Caption = Sheet3.Cells(m + 1, 2)
Me.Label5.Caption = Sheet3.Cells(m + 1, 3)
Me.Label7.Caption = Sheet3.Cells(m + 1, 4)
Me.Label9.Caption = Sheet3.Cells(m + 1, 5)
Me.Label11.Caption = Sheet3.Cells(m + 1, 6)
Me.Label13.Caption = Sheet3.Cells(m + 1, 7)
Me.Label15.Caption = Sheet3.Cells(m + 1, 8)
Me.Label17.Caption = Sheet3.Cells(m + 1, 9)
Me.Label19.Caption = Sheet3.Cells(m + 1, 10)
Me.Label26.Caption = Sheet3.Cells(m + 1, 11)
l = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
If l < 2 Then l = 2
For i = 2 To l
If Sheet1.Cells(i, 2) = id Then
dictionary.Add Sheet1.Cells(i, 18).Value, 1
End If
Next
Me.ListBox1.List = dictionary.keys
End If
m = m + 1
Loop
Else
End If
If Me.TextBox1.Value = "" Then
Label3.Caption = ""
Label13.Caption = ""
Label5.Caption = ""
ListBox1.Clear
Label7.Caption = ""
Label9.Caption = ""
TextBox2.Value = ""
Label11.Caption = ""
Label15.Caption = ""
Label17.Caption = ""
Label19.Caption = ""
Label26.Caption = ""
OptionButton3.Value = False
OptionButton2.Value = False
OptionButton1.Value = False
End If
End Sub
[\CODE]
Thanks!