Dim id As String, i As Integer, j As Integer, flag As Boolean
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdClear_Click()
ClearForm
End Sub
Private Sub cmdUpdate_Click()
EditAdd
End Sub
Private Sub Reg1_Change()
GetData
End Sub
Private Sub UserForm_Initialize()
TextBox1.SetFocus
End Sub
Sub GetData()
If IsString(UserForm1.TextBox1.Value) Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
End Sub
Sub ClearForm()
For j = 1 To 3
frmLookup.Controls("TextBox" & j).Value = ""
Next j
End Sub
Sub EditAdd()
Dim emptyRow As Long
If UserForm1.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 4 To 10
Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
12
i = i + 1
Loop
If flag = False Then
For j = 1 To 3
Cells(emptyRow, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
End If
End Sub