Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Navigating a recordset using Pageup and Pagedown

Posted on 2002-04-29
7
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6977961
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 70

Expert Comment

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

Author Comment

by:svetlana2k
ID: 6978567
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:svetlana2k
ID: 6981129
What is the value returned when I press pageup or down please

Svetlana2k
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 6981864
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
ID: 6981989
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 70

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 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