Link to home
Start Free TrialLog in
Avatar of svetlana2k
svetlana2k

asked on

Navigating a recordset using Pageup and Pagedown

Does anyone know how to move through a recordset using the Pagup and Page Down keys

Svet
Avatar of iboutchkine
iboutchkine

Set the Pagesize to a number so that the total
recordset will be splits into pages
by using

LocalSearchResult.PageSize = 14
here each page will have 14 rows

then u can find out the total number pages by

LocalSearchResult.PageCount

if u want to list a specified page use

LocalSearchResult.AbsolutePage = 25

this will directly move the page number to 25th page and then the 25th page rows can be listed.


'Here is an example how to page recordset 10 records at a time

Private m_CombinedNames As String

' Display the next 10 records.
Private Sub cmdNext_Click()
Dim db_file As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim txt As String
Dim i As Integer
Dim sSQL As String

    ' Get the database name.
    db_file = App.Path
    If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
    db_file = db_file & "People.mdb"

    ' Open a connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & db_file & ";" & _
        "Persist Security Info=False"
    conn.Open

    ' Get the next 10 records.
    sSQL = "SELECT TOP 10 * FROM Employees " & _
        "WHERE LastName + ',' + FirstName > " & _
        "'" & m_CombinedNames & "' ORDER BY LastName, FirstName"
    Set rs = conn.Execute(sSQL)
    ' Display the records.
    Do Until rs.EOF
        i = i + 1
        txt = txt & vbCrLf & _
            Format$(rs!EmployeeId, "@@@") & " " & _
            Format$(rs!LastName, "!@@@@@@@@@@@@@") & _
            Format$(rs!FirstName, "!@@@@@@@@@@@@@")
        m_CombinedNames = rs!LastName & "," & rs!FirstName
        rs.MoveNext
    Loop

    ' See if we ran out of records.
    If i < 10 Then
        txt = txt & vbCrLf & "<END>"
        cmdNext.Enabled = False
    End If

    ' Display the data.
    If Len(txt) > 0 Then txt = Mid$(txt, 3)
    txtEmployees.Text = txt
End Sub

' Display the first 10 records.
Private Sub cmdList_Click()
    ' Reset m_CombinedNames
    ' to select the first record.
    m_CombinedNames = ","

    ' Get the next 10 records.
    cmdNext.Enabled = True
    cmdNext_Click
End Sub

Private Sub Form_Load()
    ' Reset m_CombinedNames
    ' to select the first record.
    m_CombinedNames = ","
End Sub




Avatar of Éric Moreau
use a gid control. you don't have anything to write.
Avatar of svetlana2k

ASKER

Thanks
emoreau
Agrid control would not suit. There are too many fields to display.

I am using a set of labels to display the data.

iboutchkine

I am just displaying one record at a time. The user can click a next button but some user prefer to hit the pageup pagedown buttons on their keyboards because this is what they were used to in their old system.


Any more ideas experts.

All help is most appreciated.

I have already got ideas for other things from iboutchkine's code. So I am always grateful.

Svetlana2k
What is the value returned when I press pageup or down please

Svetlana2k
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great emoreau
This is exactly what I wanted. Can you recomend a good site where I can get code such as this.

Svetlana2k
You will actually find them into the VB help files.