Good day guys!

I just want a little help about recordset navigation to act when i click Previous and Next button. I have created the navigation code but it jumps the records on a table..My code below.

'==========================In class module(clsCheque_Navigation)========================
Option Explicit
Private Nav_chkno                   As String       'Store current page check no.
Private Nav_Recordset               As Recordset    'Reference recordset where we will perform the paging

Private nav_mover                   As Long

'Class Starter
Public Sub Initialize_Navigation(ByRef srcRecordset)
Set Nav_Recordset = srcRecordset

End Sub

Public Sub Navigate_Recordset(onprevious As Boolean, onnext As Boolean)
If onprevious = True Then
   nav_mover = nav_mover - 1
End If

If onnext = True Then
    nav_mover = nav_mover + 1
End If

'navigate & show the record
Show_NavRecord
End Sub

Private Sub Show_NavRecord()

    If Nav_Recordset.eof = True Then
        Nav_Recordset.Close
        Set Nav_Recordset = Nothing
        Exit Sub
    End If
    
    If nav_mover > Nav_Recordset.RecordCount - 1 Then
       nav_mover = 0
    End If
    
    If nav_mover < 0 Then
       nav_mover = Nav_Recordset.RecordCount - 1
    End If
    
    Nav_Recordset.Move nav_mover
    Nav_chkno = Nav_Recordset!checkno
    
End Sub

'Return the current chkno
Public Function Get_ChequeNo() As String
    Get_ChequeNo = Nav_chkno
End Function

Private Sub Class_Initialize()
nav_mover = 0
Nav_chkno = vbNullString
End Sub

Private Sub Class_Terminate()
nav_mover = 0
Nav_chkno = vbNullString
End Sub

'================================In Form Load====================================
option explicit
Dim pagin_nav                 As New clsCheque_Navigation

If pagingrs.State = adStateOpen Then pagingrs.Close
   pagingrs.CursorLocation = adUseClient
   pagingrs.Open "Select * from tbl_qb_account_remittances_summary", strConnection, adOpenStatic, adLockReadOnly
 
   pagin_nav.Initialize_Navigation pagingrs

'================================In Previous button Click===============================
pagin_nav.Navigate_Recordset true,false
'==================================In Next button Click=================================
pagin_nav.Navigate_Recordset false,true

Thank you for helping.

[yoda voice]over complicate things, you do[/yoda voice]

Okay, well maybe not, but using the move method to navigate is your problem...(1+1=2 so move 2 will skip a record...)

You should use the movefirst, moveprevious, movenext, and movelast properties and things will be a lot easier for you (but keep the counter variable, add a recordcount variable for testing if you wish, and things should work out)...

Good Luck

Thanks. But whats the most possible fastest way to look this records? I'm having thousands of records in a table to navigate too. And also, can you show the simplest solution if i made my solution complicated.?

Thanks again.!!

reread that 3rd sentence...

thanks. If its the most fastest way then ill go for it.

This solved..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.