Report gets run-time error "2427"

J

JimN

A report, with a subreport, has an "On Print" event to the MainReport. Then
"Run-Time Error "2427": You entered an expression that has no value. ",
appears and on "Debug" the code line: "If
Left([Reports]![MainReport]![SubReport].[Report]![Course#],1)=â€8†Then" is
highlighted. The "Help" button brings up a blank screen. The source for both
forms has data. What is the cause and fix? The coding is as follows:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Left([Reports]![MainReport]![SubReport].[Report]![Course#],1)=â€8†Then
Reports!MainReport!SubReport.Report!SupplyFee=0
Else
Reports!MainReport!SubReport.Report!SupplyFee=20
End If
 
A

Allen Browne

If there are no records to print in a subreport for the record in the main
report, Access prints nothing for the subreport. If you code tries to refer
to the text box in the subreport, it does not exist, and so your code
generates an error.

To avoid that, test the HasData property of the subreport before referring
to the controls:
With Me.[SubReport].Report
If .HasData Then
If ![Course#] = "8" Then
!SupplyFee = 0
Else
!SupplyFee = 20
End If
End If
End With

It might be easier to use this as the Control Source for SupplyFee text box
in the subreport, with no code needed:
=IIf([Course#]="8", 0, 20)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top