Why getting runtime error 440 - Automation Error

I have the following code in a GroupHeader on print event.  But the code stalls and gives me a runtime error 440 - Automation Error.  When I debug, this line is highlighted in yellow:

Me.Text35 = Me.Text45 - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumCurrentPeriod]

And when I hover over the Me.Text35 part of that line is indicated Null.

How can I overcome this issue?

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
On Error GoTo Err_GroupHeader0_Print

    If [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report].HasData Then
        Me.Text35 = [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report]![txtSumCurrentPeriod] - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumCurrentPeriod]
        Me.Text36 = [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report]![txtSumSamePeriodLastYear] - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumSamePeriodLastYear]
        Me.Text37 = [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report]![txtSumYearToDate] - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumYearToDate]
        Me.Text38 = [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report]![txtSumLastYearYearToDate] - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumLastYearYearToDate]
        Exit Sub
    End If

    If [Reports]![Income Statement].[Report]![subrptIncomeStatementINCOME].[Report].HasData = False Then
        Me.txtCurrentPeriodSumFromExpense = 0
        Me.txtSamePeriodFromLastYearFromExpense = 0
        Me.txtYearToDateFromExpense = 0
        Me.txtYearToDateLastYEarFromExpense = 0

        Me.Text45 = 0
        Me.Text46 = 0
        Me.Text47 = 0
        Me.Text48 = 0

        Me.Text35 = Me.Text45 - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumCurrentPeriod]
        Me.Text36 = Me.Text46 - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumSamePeriodLastYear]
        Me.Text37 = Me.Text47 - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumYearToDate]
        Me.Text38 = Me.Text48 - [Reports]![Income Statement].[Report]![subrptIncomeStatementEXPENSE].[Report]![txtSumLastYearYearToDate]
    End If

    Exit Sub

    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_GroupHeader0_Print
End Sub

Open in new window

Who is Participating?
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Steve,

also test the expense subreport for HasData

perhaps that section should be in an ELSE clause of the first IF?

    If me.[subrptIncomeStatementINCOME].[Report].HasData = True Then
       If me.[subrptIncomeStatementEXPENSE].[Report].HasData Then
       End if
   end if

Open in new window

I substituted Me (assuming you are in the code behind the report) for [Reports]![Income Statement].[Report] -- that is not right anyway. Main reports do not have .report after their name. That is only done for subreports and subforms because they are in controls that are containers that also have properties such as Left, Top, Width, Height, ...

Dale FyeCommented:
I've never tried to do this, but it may be that the subreport has not been rendered yet during the Print event of the group header, and therefore you cannot reference the controls on the subreport.

Try moving those textboxes that are in the GroupHeader section to the GroupFooter, and see whether it works from there.  If that works, and placing those controls in the group footer doesn't meet your needs, then you will likely have to develop a recordset in the group header Print event that returns the values which would be associated with the current group, to replicate the values that would eventually showup in the subreport.
SteveL13Author Commented:
I’m traveling today but wanted to get point awarded. Both replies I found very worthwhile. I will post my solution when I return on Tuesday.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Steve ~ happy to help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.