Office中国论坛/Access中国论坛

标题: Access报表问题求救 [打印本页]

作者: kunn82    时间: 2009-3-17 15:46
标题: Access报表问题求救
最近使用Access2003,想调用数据库中的数据生成一个report,发现一个比较奇怪的问题,向大家请教   

我首先创建了一个form一个report, frm确认键的响应代码很简单是这样的:

Dim rpt As Report, ctlNew As Control
Dim tctl As Control

'''这部分是清空report中上次生成的已有的一些控件,但不清空footer中的pagename
DoCmd.OpenReport "rptA3", acViewDesign
    Set rpt = Reports![rptA3]
errordel:
    For Each tctl In rpt.Controls
        If tctl.Name = "pagename" Then
            GoTo a1
        End If
        DeleteReportControl rpt.Name, tctl.Name
a1:    Next tctl
    If rpt.Controls.count > 1 Then GoTo errordel
    rpt.BorderStyle = 1
    rpt.Section(acDetail).Height = 15

'''下面就是创建要在该report上显示的label
Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 2700, 100, 5000, 600)
    ctlNew.Caption = "你好"
    ctlNew.FontBold = True
    ctlNew.FontName = "黑体"
    ctlNew.FontSize = 24
    ctlNew.TextAlign = 2
    ctlNew.SizeToFit
    Set ctlNew = Nothing   

    Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 500, 800, 800, 300)
    ctlNew.Caption = "周期:"
    ctlNew.FontBold = True
    ctlNew.FontName = "黑体"
    ctlNew.FontSize = 10
    ctlNew.SizeToFit
    Set ctlNew = Nothing   

    Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 1500, 800, 1500, 300)
    ctlNew.Caption = DLookup("codename", "tblcode", "codetype='Cycle' and codeNo='" & Me.ComrentDate.value & "'")
    ctlNew.FontName = "黑体"
    ctlNew.FontSize = 10
    ctlNew.SizeToFit
    Set ctlNew = Nothing   

'''然后保存,并打开report
    DoCmd.Save acReport, rpt.Name
    DoCmd.OpenReport rpt.Name, acViewPreview
    DoCmd.Maximize

在实际操作过程中,我打开form点击确认,报表便生成并最大化,但是我关闭报表再点击确认,如此反复多次后,就会出现报表打不开的问题
此时我在编辑界面双击rptA3,也打不开了,提示The expression on format you entered as the event property setting produced the following error:There isn't enough memory to complete the automation object on the | object.
在开发界面编译时,弹出窗口提示out of memory
作者: 红尘如烟    时间: 2009-3-18 13:40
  1. Dim rpt As Report, ctlNew As Control
  2. Dim tctl As Control

  3. '''这部分是清空report中上次生成的已有的一些控件,但不清空footer中的pagename
  4. DoCmd.OpenReport "rptA3", acViewDesign
  5.     Set rpt = Reports![rptA3]
  6. errordel:
  7.     For Each tctl In rpt.Controls
  8.         If tctl.Name <> "pagename" Then
  9.         DeleteReportControl rpt.Name, tctl.Name
  10.         End If
  11.     Next
  12.    
  13.     rpt.BorderStyle = 1
  14.     rpt.Section(acDetail).Height = 15

  15. '''下面就是创建要在该report上显示的label
  16. Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 2700, 100, 5000, 600)
  17.     With ctlNew
  18.         .Caption = "你好"
  19.         .FontBold = True
  20.         .FontName = "黑体"
  21.         .FontSize = 24
  22.         .TextAlign = 2
  23.         .SizeToFit
  24.     End With

  25.     Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 500, 800, 800, 300)
  26.     With ctlNew
  27.         .Caption = "周期:"
  28.         .FontBold = True
  29.         .FontName = "黑体"
  30.         .FontSize = 10
  31.         .SizeToFit
  32.     End With

  33.     Set ctlNew = CreateReportControl(rpt.Name, acLabel, acDetail, , , 1500, 800, 1500, 300)
  34.     With ctlNew
  35.         .Caption = DLookup("codename", "tblcode", "codetype='Cycle' and codeNo='" & Me.ComrentDate.Value & "'")
  36.         .FontName = "黑体"
  37.         .FontSize = 10
  38.         .SizeToFit
  39.     End With
  40. '''然后保存,并打开report
  41.     DoCmd.Save acReport, rpt.Name
  42.     DoCmd.OpenReport rpt.Name, acViewPreview
  43.     DoCmd.Maximize
  44.    
  45.     Set rpt = Nothing
  46.     Set ctlNew = Nothing
  47.     Set tctl = Nothing
复制代码





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3