|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
感谢分享,但楼主最好能简单分析一下思路:比如本例就是通过创建一个临时的数据源表tblreport,并通过其中的pagenum字段来选择报表的数据源。
代码写得很好,我自己改了下,也可以用:- Private Sub cmdPrint_Click()
- On Error GoTo Err_cmdPrint_Click
- Dim i As Long
- Dim myLines As Integer
- Dim CurrentPage As Integer
- Dim stDocName As String
- Dim rst As Object
- myLines = Forms!frmOpen!CobLines
- DoCmd.SetWarnings False
- ' DoCmd.RunSQL "DELETE tblReport.* FROM tblReport"
- DoCmd.RunSQL "DELETE FROM tblReport"
- '按ID升序追加到表
- ' DoCmd.RunSQL "INSERT INTO tblReport ( ID, Model, PcName, Composition, Specification, Price ) " _
- ' & "SELECT ID, Model, PcName, Composition, Specification, Price " _
- ' & "FROM computer ORDER BY ID"
- DoCmd.RunSQL "INSERT INTO tblReport " _
- & "SELECT * " _
- & "FROM computer ORDER BY ID"
- Set rst = CurrentDb.OpenRecordset("tblReport", dbOpenDynaset)
- ' rst.MoveFirst
- i = 0
- Do Until rst.EOF
- rst.Edit
- rst!pageNum = (i - i Mod myLines) / myLines + 1
- rst.Update
- i = i + 1
- rst.MoveNext
- Loop
- rst.Close
- Set rst = Nothing
- stDocName = "rpt报表"
- DoCmd.OpenReport stDocName, acPreview
- Exit_cmdPrint_Click:
- Exit Sub
- Err_cmdPrint_Click:
- MsgBox Err.Description
- Resume Exit_cmdPrint_Click
- End Sub
复制代码 |
|