[access报表]报表补空行另类打印方法
时 间:2009-05-13 22:16:04
作 者:caoguangyao ID:3606 城市:广州
摘 要:左边命令按纽功能:
"村居ID"不为空时为单一打印
否则为连续打印
1 补空行
2 显示本村人数
3 显示页码
正 文:
1、创建临时表(临时初婚表)
2、创建两个查询,“查询1”用于求得每组中的记录数,“初婚表打印查询”用作报表“初婚表打印2”的记录源
3、创建报表“初婚表打印2”,设置分组(ID村居)页眉和页脚
4、报表“初婚表打印2”格式化代码:
Option Compare Database
Option Explicit
Dim k, T1, T2 As Integer 'T1为组中的当前页数,T2为组中的总页数
Dim j, j1 As Integer
Dim Stemp As String
Private Sub 页面页眉_Format(Cancel As Integer, FormatCount As Integer)
Me!i = Me!i - 1
End Sub
Private Sub 主体_Format(Cancel As Integer, FormatCount As Integer)
Me!i = Me!i + 1 '行数计数累加
End Sub
Private Sub 主体_Print(Cancel As Integer, PrintCount As Integer)
On Error GoTo Err_主体_Print
j1 = 12 '设定每页打印行数
If i <= j1 - 1 Then
T1 = 1
Else
If i Mod j1 = 0 Then
k = Int(i / j1)
For j = 1 To k
T1 = j
Next
Else
T1 = k + 1
End If
End If
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Stemp = "select * from 临时初婚表 where [村居ID]='" & Me.[村居ID] & "'"
rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rs.RecordCount <= j1 Then
T2 = 1
Else
T2 = Int(rs.RecordCount / j1) ' 如果不要补空行,则 T2=Int(rs.RecordCount / j1) +1,其实因为补了空行,每组的记录数(包括空行数),都是j1的倍数
End If
T0 = "第" & [T1] & "页/共" & [T2] & "页 "
rs.Close
Set rs = Nothing
Exit_主体_Print:
Exit Sub
Err_主体_Print:
MsgBox Err.Description
Resume Exit_主体_Print
End Sub
Private Sub 组页眉0_Format(Cancel As Integer, FormatCount As Integer)
Me!i = 0 '保证分组后,序号从1开始计数
End Sub
5、“连续打印”单击事件:
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim i, i2, i3 As Long
Dim k As Long '打印总行数
Dim j As Integer
j = 12 '每页打印行数
Dim Stemp As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Stemp = "select * from 临时初婚表"
rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
Stemp = "select * from 初婚表"
rs2.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Dim rs3 As ADODB.Recordset
Set rs3 = New ADODB.Recordset
Stemp = "Select 初婚表.村居ID, Count(初婚表.[家庭编号]) AS 记录数 FROM 初婚表 GROUP BY 初婚表.村居ID"
rs3.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'--------打印前,清空临时表中的记录
If rs.RecordCount > 0 Then
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
rs.Delete 1
rs.Update
rs.MoveNext
Next
End If
'--------把所有要打印的记录,插入到临时表中
rs2.MoveFirst
For i = 0 To rs2.RecordCount - 1
rs.AddNew
rs![ID] = rs2![ID]
rs![村居ID] = rs2![村居ID]
rs![村居] = rs2![村居]
rs![家庭编号] = rs2![家庭编号]
rs![育妇姓名] = rs2![育妇姓名]
rs![出生日期] = rs2![出生日期]
rs![婚姻日期] = rs2![婚姻日期]
rs![婚姻状况] = rs2![婚姻状况]
rs![配偶姓名] = rs2![配偶姓名]
rs![配偶出生日期] = rs2![配偶出生日期]
rs![配偶婚姻状况] = rs2![配偶婚姻状况]
rs![婚姻备注] = rs2![婚姻备注]
rs![登记日期] = rs2![登记日期]
rs![变更日期] = rs2![变更日期]
rs.Update
rs2.MoveNext
Next
'--------确定要补的空行数,并插入到临时表中
rs3.MoveFirst
For i = 0 To rs3.RecordCount - 1
If rs3![记录数] Mod j = 0 Then
k = rs3![记录数]
Else
k = (Int(rs3![记录数] / j) + 1) * j
End If
For i3 = 1 To k - rs3![记录数]
rs.AddNew
rs![村居ID] = rs3![村居ID]
rs.Update
Next
rs3.MoveNext
Next
'--------以预览的方式 打开报表
DoCmd.OpenReport "初婚表打印2", acViewPreview
rs.Close
Set rs = Nothing
rs2.Close
Set rs2 = Nothing
rs3.Close
Set rs3 = Nothing
Exit_Command10_Click:
Exit Sub
Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End Sub
6、组合框[村居ID]的更新事件:
Private Sub 村居ID_AfterUpdate()
Call Command10_Click
End Sub
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)