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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
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.
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, ...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.