|
http://access911.myetang.com/study/a_rpt003.htm文件下载
示例报表打印与预览vba中
Set TableA = DB.OpenRecordset("本月", dbOpenSnapshot)
其中本月查询的日期直接指定为#2001-1-1# ,如果日期为form指定的日期,应如何解决?
我试了很久,都不能传递参数.
Private Sub Command2_Click()
On Error GoTo Err_command2_Click '产生错误则转到Err_command2_Click行
'请参看我主页上《学习》栏目中文章《如何制作复杂报表——利用Excel输出复杂报表》
'其他数据的输出也可以参考下面的程序
Dim xlApp As Excel.Application
Dim xlBook As Workbook, xlSheet As Worksheet
Dim TableA As Recordset, DB As Database, Wks As Workspace
Dim X1 As Long, X2 As Long, Y As Long
'将“rpt.xls”复制一个备份到“temp.xls”
Dim strSource As String, strDestination As String
strSource = "m:\rpt.xls"
strDestination = "m:\temp.xls"
FileCopy strSource, strDestination
'将“temp.xls”打开
Set xlApp = CreateObject("Excel.Application")
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("m:\temp.xls")
Set xlSheet = xlBook.Worksheets(1)
'打开数据表
Set Wks = Workspaces(0)
Set DB = CurrentDb()
Set TableA = DB.OpenRecordset("本月", dbOpenSnapshot) '打开查询
TableA.MoveFirst
Do Until TableA.EOF = True
Select Case TableA!街道
Case "城南"
X1 = 6
X2 = 15
Case "城西"
X1 = 7
X2 = 16
Case "城北"
X1 = 8
X2 = 17
Case "城东"
X1 = 9
X2 = 18
Case "城郊"
X1 = 10
X2 = 19
End Select
xlSheet.cells(X1, 3) = TableA!申报户数
xlSheet.cells(X1, 4) = TableA!注销户数
xlSheet.cells(X1, 5) = TableA!中小修合计
xlSheet.cells(X1, 6) = TableA!中修
xlSheet.cells(X1, 7) = TableA!小修维修
xlSheet.cells(X1, 8) = TableA!效益面积
xlSheet.cells(X1, 9) = TableA!修理费支出
xlSheet.cells(X1, 10) = TableA!返工户数
xlSheet.cells(X1, 11) = TableA![占%]
xlSheet.cells(X2, 2) = TableA!大修申报户数
xlSheet.cells(X2, 3) = TableA!完成大修理
xlSheet.cells(X2, 4) = TableA!大修效益面积
xlSheet.cells(X2, 5) = TableA!大修修理费支出
xlSheet.cells(X2, 7) = TableA!房改房申报户数
xlSheet.cells(X2, 8) = TableA!房改房完成修理
xlSheet.cells(X2, 9) = TableA!房改房效益面积
xlSheet.cells(X2, 10) = TableA!房改房修理费支出
TableA.MoveNext
Loop
TableA.close
xlBook.Save
xlSheet.PrintPreview
xlBook.close
xlApp.Quit
Exit_command2_Click:
Exit Sub
Err_command2_Click:
MsgBox "异常终止!"
Resume Exit_command2_Click
End Sub
[此贴子已经被作者于2002-11-10 20:58:07编辑过]
|
|