Solved

Navigating a recordset using Pageup and Pagedown

Posted on 2002-04-29
7
147 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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