Move next record problem

malrvel

New Member
Joined
Aug 9, 2016
Messages
8
I have a userform for search record in worksheet. The search code is below for refrence
Code:
Sub searchData()

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


End Sub

The above code is written in change event of Textbox1, its works fine. Now I want to move next record from current record. so I simply write code below in cmdnext button. the code is
Code:
Private Sub cmdnext_Click()currentrow = i
currentrow = currentrow + 1
            flag = True
 For j = 1 To 34
        UserForm1.Controls("TextBox" & j).Value = cells(currentrow, j).Value
     Next j
End Sub

when i click the command button button it wouln't move to next record.

kindly help in this task.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
Private Sub cmdnext_Click()
    currentrow = i
    currentrow = currentrow + 1
    flag = True
    For j = 1 To 34
        UserForm1.Controls("TextBox" & j).Value = cells(currentrow, j).Value
    Next j
End Sub
The first line of that code is:
Code:
currentrow = i
But you have not defined i anywhere in that procedure.
So unless you have set up i to be a Global Variable, its value is zero, and will never change within this procedure.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top