使用Recordset的AbsolutePage, PageCount, PageSize来分页:AbsolutePage, PageCount, and PageSize Properties Example This example uses the AbsolutePage, PageCount, and PageSize properties to display names and hire dates from the Employee table, five records at a time.Public Sub AbsolutePageX()
Dim rstEmployees As ADODB.Recordset Dim strCnn As String Dim strMessage As String Dim intPage As Integer Dim intPageCount As Integer Dim intRecord As Integer ' Open a recordset using a client cursor ' for the employee table. strCnn = "Provider=sqloledb;" & _ "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; " Set rstEmployees = New ADODB.Recordset ' Use client cursor to enable AbsolutePosition property. rstEmployees.CursorLocation = adUseClient rstEmployees.Open "employee", strCnn, , , adCmdTable
' Display names and hire dates, five records ' at a time. rstEmployees.PageSize = 5 intPageCount = rstEmployees.PageCount For intPage = 1 To intPageCount rstEmployees.AbsolutePage = intPage strMessage = "" For intRecord = 1 To rstEmployees.PageSize strMessage = strMessage & _ rstEmployees!fname & " " & _ rstEmployees!lname & " " & _ rstEmployees!hire_date & vbCr rstEmployees.MoveNext If rstEmployees.EOF Then Exit For Next intRecord MsgBox strMessage Next intPage rstEmployees.CloseEnd Sub
This example uses the AbsolutePage, PageCount, and PageSize properties to display names and hire dates from the Employee table, five records at a time.Public Sub AbsolutePageX()
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim strMessage As String
Dim intPage As Integer
Dim intPageCount As Integer
Dim intRecord As Integer ' Open a recordset using a client cursor
' for the employee table.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstEmployees = New ADODB.Recordset
' Use client cursor to enable AbsolutePosition property.
rstEmployees.CursorLocation = adUseClient
rstEmployees.Open "employee", strCnn, , , adCmdTable
' Display names and hire dates, five records
' at a time.
rstEmployees.PageSize = 5
intPageCount = rstEmployees.PageCount
For intPage = 1 To intPageCount
rstEmployees.AbsolutePage = intPage
strMessage = ""
For intRecord = 1 To rstEmployees.PageSize
strMessage = strMessage & _
rstEmployees!fname & " " & _
rstEmployees!lname & " " & _
rstEmployees!hire_date & vbCr
rstEmployees.MoveNext
If rstEmployees.EOF Then Exit For
Next intRecord
MsgBox strMessage
Next intPage
rstEmployees.CloseEnd Sub