Question : A custom macro in this report has failed to run, and is preventing the report from rendering.

I have a report that has the attached code in order to start a new page number for each item group (e.g. Customer 1 Page 1 of 3 for the first group, then Customer 2 Page 1 of 2 for the second group and so on). However, when attempting to Print or Save this report as PDf I get the following error message: A custom macro in this report has failed to run, and is preventing the report from rendering. I can preview the report and then print it or save it as PDF with no problem.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Option Compare Database
Option Explicit
Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer
 
 
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
Dim i As Integer
  If Me.Pages = 0 Then
    ReDim Preserve GrpArrayPage(Me.Page + 1)
    ReDim Preserve GrpArrayPages(Me.Page + 1)
    GrpNameCurrent = Me.Customer
    If GrpNameCurrent = GrpNamePrevious Then
        GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
        GrpPages = GrpArrayPage(Me.Page)
            For i = Me.Page - ((GrpPages) - 1) To Me.Page
                GrpArrayPages(i) = GrpPages
            Next i
    Else
        GrpPage = 1
        GrpArrayPage(Me.Page) = GrpPage
        GrpArrayPages(Me.Page) = GrpPage
    End If
  Else
    Me.ctlGrpPages = "Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
  End If
  GrpNamePrevious = GrpNameCurrent
End Sub

Answer : A custom macro in this report has failed to run, and is preventing the report from rendering.

Actually there are now 4 Report views:
(The term "Normal view" is a vague term)

1. Report View, which you are describing in #1.
2. Print Preview
3. Layout View
4. Design view

In "Report View" no code will run at all.
So your custom code will not run, possibly generating this error, as the Report  needs the code to properly "Render" (draw) the report.

If this is indeed the issue, then your only option would seem to be that you use Print Preview.

JeffCoachman
Random Solutions  
 
programming4us programming4us