Solved

Navigating a recordset using Pageup and Pagedown

Posted on 2002-04-29
7
145 Views
Last Modified: 2010-05-02
Does anyone know how to move through a recordset using the Pagup and Page Down keys

Svet
0
Comment
Question by:svetlana2k
  • 3
  • 3
7 Comments
 
LVL 28

Expert Comment

by:iboutchkine
Comment Utility
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




0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
use a gid control. you don't have anything to write.
0
 

Author Comment

by:svetlana2k
Comment Utility
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
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:svetlana2k
Comment Utility
What is the value returned when I press pageup or down please

Svetlana2k
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
Comment Utility
you can trap page up and down keys in the KeyDown (or KeyUp) event of controls:

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyPageUp Then
        Debug.Print "Text1_KeyDown : page up"
    ElseIf KeyCode = vbKeyPageDown Then
        Debug.Print "Text1_KeyDown : page down"
    End If
End Sub
0
 

Author Comment

by:svetlana2k
Comment Utility
Great emoreau
This is exactly what I wanted. Can you recomend a good site where I can get code such as this.

Svetlana2k
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
You will actually find them into the VB help files.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now