Office中国论坛/Access中国论坛
标题:
如何依据数据手动来对报表进行添加空行
[打印本页]
作者:
yanwei82123300
时间:
2012-7-10 22:06
标题:
如何依据数据手动来对报表进行添加空行
今天从论坛上发现一个比较不错的例子:是手动添加报表空行,但是格式是MDE的没法学习到代码,请问哪位老师可以知道是如何制作的,请分享一下,谢谢
作者:
koutx
时间:
2012-7-11 11:23
无非是给订单表中插指定多的空行再删除而已,你没看有一个删除查询(sc)吗。
你指定要插入的空行数存在订单设置表中的kh字段
在报表的打开和关闭事件中估计是如下代码:
大致如下:
Private Sub Report_Open(Cancel As Integer)
Dim sz As Integer
sz = Nz(DLookup("kh", "报表设置", "kh >= 0"), 0)
If sz > 0 Then
For i = 1 To sz
DoCmd.RunSQL "INSERT INTO 订单表 (订单数量) VALUES (Null)"
Next
End If
Dim sqlS As String
sqlS = "SELECT 订单编号, 客户名称, 订单数量, 订单日期, 备注 FROM 订单表"
Me.RecordSource = sqlS
End Sub
Private Sub Report_Close()
DoCmd.OpenQuery "sc"
End Sub
作者:
roych
时间:
2012-7-11 17:23
好像是t小宝的作品……请自行创建模块处理。
Option Compare Database
Option Explicit
'************************************************************************************************
'参数说明:
'ReportSheet (rpt, LeftControl, RightControl, RowsOfPage, Style)
' rpt:必选,报表名称
' LeftControl:必选,最左边控件名称,用于确定左边距。
' RightControl:必选,最右边控件名称,用于确定右边距。
' RowsOfPage:可选,为每页指定行数
' Style:可选,0为方框,1为仅画横线,2为仅画竖线。
'调用说明:
'在报表中“打印页前”事件中调用:=ReportSheet (rpt, [左控件名称], [右控件名称], RowsOfPage, Style)
'*************************************************************************************************
Public Function ReportSheet(rpt As Report, LeftControl As Control, RightControl As Control, _
Optional RowsOfPage As Integer, Optional Style As Integer = 0)
On Error Resume Next
Dim intI As Integer
Dim lngTop As Long
Dim lngBottom As Long
Dim lngLeft As Long
Dim lngRight As Long
Dim lngRowHeight As Long
Dim lngRows As Long
Dim lngRowTop As Long
Dim lngBottomMax As Long
Dim ctl As Control
With rpt
lngRowHeight = .Section(acDetail).Height
lngTop = .Section(acPageHeader).Height
If .Page = 1 Then lngTop = lngTop + .Section(acHeader).Height
lngBottomMax = .Section(acPageFooter).Height
lngBottomMax = .ScaleHeight - lngBottomMax
End With
lngRows = Int((lngBottomMax - lngTop) / lngRowHeight)
If RowsOfPage > 0 Then
If RowsOfPage < lngRows Then lngRows = RowsOfPage
End If
lngBottom = lngTop + lngRowHeight * lngRows
lngLeft = rpt.ScaleWidth
For Each ctl In rpt.Section(acDetail).Controls
If lngLeft > ctl.Left Then lngLeft = ctl.Left
If lngRight < ctl.Left + ctl.Width Then lngRight = ctl.Left + ctl.Width
If Style <> 1 Then rpt.Line (ctl.Left, lngTop)-(ctl.Left, lngBottom)
Next
If Style <> 1 Then rpt.Line (lngRight, lngTop)-(lngRight, lngBottom)
If Style <> 2 Then
For intI = 0 To lngRows
rpt.Line (lngLeft, lngTop + lngRowHeight * intI)-(lngRight, lngTop + lngRowHeight * intI)
Next
End If
End Function
复制代码
作者:
yanwei82123300
时间:
2012-7-11 20:24
谢谢上面二位老师的帮助!
作者:
t小宝
时间:
2012-7-11 20:40
那个MDE不是我的啦,论坛上有很多报表加空行的方法都是有源码的,自己下来研究一下吧
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3