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小宝的作品……请自行创建模块处理。
  1. Option Compare Database
  2. Option Explicit

  3. '************************************************************************************************
  4. '参数说明:
  5. 'ReportSheet (rpt, LeftControl, RightControl, RowsOfPage, Style)
  6. '           rpt:必选,报表名称
  7. '           LeftControl:必选,最左边控件名称,用于确定左边距。
  8. '           RightControl:必选,最右边控件名称,用于确定右边距。
  9. '           RowsOfPage:可选,为每页指定行数
  10. '           Style:可选,0为方框,1为仅画横线,2为仅画竖线。
  11. '调用说明:
  12. '在报表中“打印页前”事件中调用:=ReportSheet (rpt, [左控件名称], [右控件名称], RowsOfPage, Style)
  13. '*************************************************************************************************
  14. Public Function ReportSheet(rpt As Report, LeftControl As Control, RightControl As Control, _
  15.                             Optional RowsOfPage As Integer, Optional Style As Integer = 0)
  16. On Error Resume Next

  17.     Dim intI As Integer
  18.     Dim lngTop As Long
  19.     Dim lngBottom As Long
  20.     Dim lngLeft As Long
  21.     Dim lngRight As Long
  22.     Dim lngRowHeight As Long
  23.    
  24.     Dim lngRows As Long
  25.     Dim lngRowTop As Long
  26.     Dim lngBottomMax As Long
  27.    
  28.     Dim ctl As Control
  29.    
  30.     With rpt
  31.         lngRowHeight = .Section(acDetail).Height
  32.         lngTop = .Section(acPageHeader).Height
  33.         If .Page = 1 Then lngTop = lngTop + .Section(acHeader).Height
  34.         lngBottomMax = .Section(acPageFooter).Height
  35.         lngBottomMax = .ScaleHeight - lngBottomMax
  36.     End With

  37.     lngRows = Int((lngBottomMax - lngTop) / lngRowHeight)
  38.     If RowsOfPage > 0 Then
  39.        If RowsOfPage < lngRows Then lngRows = RowsOfPage
  40.     End If
  41.     lngBottom = lngTop + lngRowHeight * lngRows
  42.    
  43.     lngLeft = rpt.ScaleWidth
  44.     For Each ctl In rpt.Section(acDetail).Controls
  45.         If lngLeft > ctl.Left Then lngLeft = ctl.Left
  46.         If lngRight < ctl.Left + ctl.Width Then lngRight = ctl.Left + ctl.Width
  47.         If Style <> 1 Then rpt.Line (ctl.Left, lngTop)-(ctl.Left, lngBottom)
  48.     Next
  49.     If Style <> 1 Then rpt.Line (lngRight, lngTop)-(lngRight, lngBottom)
  50.    
  51.    
  52.     If Style <> 2 Then
  53.         For intI = 0 To lngRows
  54.             rpt.Line (lngLeft, lngTop + lngRowHeight * intI)-(lngRight, lngTop + lngRowHeight * intI)
  55.             
  56.         Next
  57.     End If
  58.         
  59. 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