malarvel
09-09-2016, 10:00 PM
I have a userform for search record in worksheet. I have placed five command button Edit,(next, previous, clear, exit). I have a code for search record in Textbox1 change event. the code is below for reference. It works fine.
Sub GetData()
If IsNumeric(UserForm1.TextBox1.Value) Then
flag = False
i = 0
Empid = UserForm1.TextBox1.Value
Do While cells(i + 1, 1).Value <> ""
If cells(i + 1, 1).Value = Empid Then
flag = True
For j = 2 To 34
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 34
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
for example i have searched employee id 104 means i entered 104 in textbox1, it display all the value in all text boxes.
Now I want to move next record from the current record position. I have a code in cmdnext button. The code is below for reference.
Private Sub cmdnext_Click()i = 0
i = i + 1
flag = True
For j = 1 To 34
UserForm1.Controls("TextBox" & j).Value = cells(i, j).Value
Next j
End Sub
Now i have clicked the command button it wouldn't move to next record and no record shown.
I have attached sample data for reference.
kindly help in this task.
Sub GetData()
If IsNumeric(UserForm1.TextBox1.Value) Then
flag = False
i = 0
Empid = UserForm1.TextBox1.Value
Do While cells(i + 1, 1).Value <> ""
If cells(i + 1, 1).Value = Empid Then
flag = True
For j = 2 To 34
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 34
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
for example i have searched employee id 104 means i entered 104 in textbox1, it display all the value in all text boxes.
Now I want to move next record from the current record position. I have a code in cmdnext button. The code is below for reference.
Private Sub cmdnext_Click()i = 0
i = i + 1
flag = True
For j = 1 To 34
UserForm1.Controls("TextBox" & j).Value = cells(i, j).Value
Next j
End Sub
Now i have clicked the command button it wouldn't move to next record and no record shown.
I have attached sample data for reference.
kindly help in this task.