Dim rst As ADODB.Recordset
Dim num As Integer '记录已输出的有效记录数-1
Dim bc As Integer '记录所需补的空记录数 ,在变,最后减为0
Dim bc2 As Integer '记录所需补的空记录数 ,一直不变
Dim totalPagenum As Integer '记录总页数
Dim recordnum As Integer '记录总记录数
Dim flag As Boolean '控制开关,控制最后一条记录的显示
Private Sub ActiveReport_ReportStart()
Set rst = GetRecordset("select * from ymjzjl") '注意这里的打开方式,recordcount
'的属性必须可用
'赋初值
num = -1
recordnum = rst.RecordCount'总记录数
bc = 10 - recordnum Mod 10
If bc = 10 Then
bc = 0
End If
bc2 = bc '需要补充的行数
If bc = 0 Then
totalPagenum = recordnum / 10'总的页数
Else
totalPagenum = recordnum / 10 + 1
End If
rst.MoveFirst
DataControl1.Recordset = rst
End Sub
Private Sub Detail_Format()
PageBreak1.Enabled = False 'PageBreak1用来控制一页只显示10条记录
num = num + 1 '已经打印的行数
If num >= recordnum - 1 And bc > 0 Then
If flag = True Then
Field2.Text = ""
Field1.Text = ""
Field3.Text = ""
Field4.Text = ""
Field5.Text = ""
End If
flag = True
rst.MovePrevious
bc = bc - 1 '还需打印的空行减1
End If
If bc = 0 And flag = True Then
Field2.Text = ""
Field1.Text = ""
Field3.Text = ""
Field4.Text = ""
Field5.Text = ""
End If
If (num + 1) Mod 10 = 0 Then
If Me.pageNumber = totalPagenum Then
MsgBox ("Last Page!") '最后一页的最后一条,这里你可以添加自己的代码
End If
If Not Me.pageNumber = totalPagenum Then
PageBreak1.Enabled = True '一页10行打印完毕,换页
End If
End If
End Sub