(Solved) – Userform Next and Previous Button – Show and go to next and previous records on Active Sheet

(solved)-–-userform-next-and-previous-button-–-show-and-go-to-next-and-previous-records-on-active-sheet

I am having trouble with next and previous buttons on a userform in excel. The problem I am having is with the command buttons searching the activesheet verus sheet1. I believe I got the code right on the next and previous buttons but I cannot get the LoadRow to load the currentrow from the active sheet. Any assistance is greatly appreciated.

Next Button Code:

Private Sub cmdnext_Click()
Dim CurrentRow As Long
     With ActiveSheet
    If CurrentRow < ActiveSheet.Cells(Rows.count, 2).End(xlUp).Row Then
    CurrentRow = CurrentRow   1
    cmdnext.Enabled = True
    LoadRow 
    If CurrentRow = 2 Then
    MsgBox "This is the first entry."
   End If
    End If
    End With
 End Sub

This is the previous button code:

Private Sub cmdprevious_Click()
 Dim CurrentRow As Long
  With ActiveSheet
   If CurrentRow > 2 Then
    CurrentRow = CurrentRow - 1
    cmdprevious.Enabled = True
    LoadRow
    If CurrentRow = 2 Then
        MsgBox "This is the first entry,"
        End If
   End If
   End With
   End Sub

This is the loadrow sub:

Private Sub LoadRow()      
   With ActiveSheet
    txtname.Text = .Cells(wrow, 1)
    txtposition.Text = .Cells(wrow, 2)
    txtassigned.Text = .Cells(wrow, 3)
    cmbsection.Text = .Cells(wrow, 4)
    txtdate.Text = .Cells(wrow, 5)
    txtjoint.Text = .Cells(wrow, 7)
    txtDAS.Text = .Cells(wrow, 8)
    txtDEROS.Text = .Cells(wrow, 9)
    txtDOR.Text = .Cells(wrow, 10)
    txtTAFMSD.Text = .Cells(wrow, 11)
    txtDOS.Text = .Cells(wrow, 12)
    txtPAC.Text = .Cells(wrow, 13)
    ComboTSC.Text = .Cells(wrow, 14)
    txtTSC.Text = .Cells(wrow, 15)
    txtAEF.Text = .Cells(wrow, 16)
    txtPCC.Text = .Cells(wrow, 17)
    txtcourses.Text = .Cells(wrow, 18)
    txtseven.Text = .Cells(wrow, 19)
    txtcle.Text = .Cells(wrow, 20)
    txtnote.Text = .Cells(wrow, 21)
   End With
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *