Solved

Navigating a recordset using Pageup and Pagedown

Posted on 2002-04-29
7
150 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

820 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