回复 4楼 xss_wl
不在窗体载入数据时候rsFirst.AbsolutePage = intPageNumber
这里出错
程序代码:
Dim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset '原始记录集
Dim rs2 As New ADODB.Recordset '每个页面的记录集
Dim intPage As Integer '当前页数
Private Sub Command1_Click()
Dim s As String
If intPage < rs1.PageCount Then '指定页面,每点一下就是下一个页面
intPage = intPage + 1
Else
MsgBox "已经是最后一页"
End If
Call rsPage(rs1, intPage) '调用分页显示
End Sub
Private Sub Form_Load()
intPage = 0
hfg.FixedCols = 0
hfg.Height = hfg.RowHeight(0) * 6 + 290 + 20
hfg.Width = hfg.CellWidth * 6 + 30 * 6
cn.Open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=book;Data Source=ZHENG"
rs1.Open "select * from 书名", cn, adOpenKeyset, adLockOptimistic, adCmdText
rs1.PageSize = 6
End Sub
无数据时候rsFirst.AbsolutePage = intPageNumber 这里出错
Private Sub rsPage(ByRef rsFirst As Recordset, ByVal intPageNumber As Integer)
Dim i As Integer, j As Integer
For i = 0 To rsFirst.Fields.Count - 1 '创建新表rs2,加入相关字段
rs2.Fields.Append rsFirst.Fields(i).Name, rsFirst.Fields(i).Type, rsFirst.Fields(i).DefinedSize, rsFirst.Fields(i).Attributes
Next i
rs2.Open
rsFirst.AbsolutePage = intPageNumber
For i = 1 To rsFirst.PageSize '把相应页的数据复制到新表rs2中
rs2.AddNew
For j = 0 To rsFirst.Fields.Count - 1
rs2.Fields(j) = rsFirst.Fields(j)
Next j
rs2.Update
rsFirst.MoveNext
If rsFirst.EOF Then Exit For '判断是否到结尾,因为最后一面,可能不是整个大小
Next i
Set hfg.DataSource = rs2
rs2.Close
End Sub
[此贴子已经被作者于2016-11-10 03:32编辑过]