Knowledge Base |

# ACC: "Out of Memory" or Low System Resources Printing Lines

Article ID: 121358

Article Last Modified on 5/6/2003

APPLIES TO

- Microsoft Access 1.0 Standard Edition
- Microsoft Access 1.1 Standard Edition
- Microsoft Access 2.0 Standard Edition

This article was previously published under Q121358
Moderate: Requires basic macro, coding, and interoperability skills.

## SYMPTOMS

When you print a form or report containing graphic lines created with the line control, you either receive an "Out of memory" error message, or you notice that Microsoft Windows system resources decrease as you print multiple forms or reports.

## CAUSE

When you print forms or reports containing graphic lines, Microsoft Access stores the image created to print the lines. The image is not cleared until you quit Microsoft Access. As you print multiple forms or reports, the Windows system resources decrease. Quitting and then restarting Microsoft Access restores the lost system resources.

## RESOLUTION

Instead of using the line control to create a line on a form or report, use a rectangle control or the borders of a text box.
The following sample code demonstrates how to open all the reports in a database and then replace all the lines controls in the reports with rectangle controls.
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

       Option Compare Database  ' Use database order for string comparisons.
       Option Explicit

       Sub ChgLinToRect (Rptname As String)
           ' Opens the report and changes lines to rectangles.
           Dim i, numctrls
           Dim rpt As Report
           Dim newrect As Control
           DoCmd OpenReport Rptname, A_DESIGN
           Set rpt = Reports(Rptname)
           numctrls = rpt.count
           For i = 0 To numctrls - 1
               If IsLineControl(rpt(i)) Then
                   ' If it is a line control then create a new rectangle
                   ' with properties like the line.

                   Set newrect = CreateReportControl(rpt.name, 101, _
                   rpt(i).section, "", "", rpt(i).left, rpt(i).top, _
                   rpt(i).width, rpt(i).height)

                   newrect.BorderStyle = rpt(i).BorderStyle
                   newrect.BorderColor = rpt(i).BorderColor
                   newrect.BorderWidth = rpt(i).BorderWidth
                   newrect.BorderLineStyle = rpt(i).BorderLineStyle
                   newrect.SpecialEffect = 0
                   ' Delete the line.
                   DeleteReportControl Rptname, rpt(i).name
                   ' Decrease counters by one.
                   i = i - 1
                   numctrls = numctrls - 1
               End If
           Next i
           DoCmd DoMenuItem 7, 0, 2
           DoCmd Close

       End Sub

       Function DoAllReps ()
          ' This function loops through all reports, changing lines to
          ' rectangles.
           Dim db As Database
           Dim i
           Set db = DBEngine.Workspaces(0).Databases(0)
           For i = 0 To db.Containers("Reports").Documents.Count - 1
               ChgLinToRect (db.Containers("Reports").Documents(i).Name)
           Next i
       End Function

       Function IsLineControl (Ctl As Control)
           ' This function tests to see if a control is a line control.
           Dim x
           On Error Resume Next
           x = Ctl.lineslant
           IsLineControl = (Err = 0)
       End Function

To run this code, call the DoAllReps() function in a module's Immediate window by typing the following line and then pressing ENTER:
`?DoAllReps()`
NOTE: There will be a great deal of screen activity caused by the property sheets and windows opening and closing.

## STATUS

This behavior no longer occurs in Microsoft Access version 7.0.

Keywords: kberrmsg kbprint kbprb KB121358