How to Change the Source Object for a Subreport with a CountThem Control

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have a report with photographs. If there are fewer than five
photographs to display in a group, I want a subreport to open that has
large photos. If there are five or more photos, I want Access to
switch to another subreport to open that has smaller photos. So the
single report will switch back and forth for the printing, depending on
the count in each section.

I placed a subreport called SelfPrintNew in a section called "GroupID"
and created a text box in the same section that adds up the number of
photos. I called it "CountThem" and put "=Count([StyleNumber])" in the
Control Source, keeping the Running Sum property set to No. (I checked
the results out without the code and it surely works correctly.)

I put this in the OnOpen property of the form:

If CountThem < 5 Then
Me.SelfPrintNew.SourceObject = "Report.SelfPrintNewrpt02sub"
Else
Me.SelfPrintNew.SourceObject = "Report.SelfPrintNewrpt01sub"
End If

Nice try, but it doesn't work. I've done this sort of thing many times
and can't quite figure out what to do correctly. I experimented quite
a lot but can't seem to fall on the solution.

I get the following error:

Run-time error '2427':
You entered an expression that has no value.
The expression may refer to an object that has no value,
such as a form,a report, or a label control.

But it is a value. It is surely not a form or report or label. If I
put a "Me." before the CountThem in the code, the same problem occurs.

When I move the code to the OnPrint of the GroupID section, I get an
error stating that it can't set this after printing has started. But I
pretty much think I need it in this GroupID section for the report to
work as I want it to.

Anyway, what is the best way to handle this? Simply put, if the
records add up to such and such, use this source object, if they add up
to that and that, use that source object.

Thanks in advance,

Matt

.



Relevant Pages

  • RE: *REPOST* If then Else Statment in Report
    ... "Duane Hookom" wrote: ... when a main report doesn't return records. ... Earlier as we found I was confused about the name of the control ... which is the name of the subreport as seen in the database window. ...
    (microsoft.public.access.reports)
  • RE: *REPOST* If then Else Statment in Report
    ... Earlier as we found I was confused about the name of the control ... with my report controls. ... "Duane Hookom" wrote: ... which is the name of the subreport as seen in the database window. ...
    (microsoft.public.access.reports)
  • RE: Should be simple but...
    ... When I look at the subreport preview, ... This does not affect my sample report because I have not input all staff, ... "Duane Hookom" wrote: ... "Aria" wrote: ...
    (microsoft.public.access.reports)
  • Re: Input Parameters - multiple invoking forms
    ... No I have have 2 different main reports which use exactly the same subreport. ... I have another problem in that two different forms activate the same report ... The InputParameters is to be used for the main ... Sylvain Lafontaine, ing. ...
    (microsoft.public.access.reports)
  • RE: Errors in Report total fields
    ... subtotal control ... Are PaymentTotal and ExpenseTotal in the REPORT footer of each subreport? ... reports to get their totals data from the fields of the report which come ...
    (microsoft.public.access.reports)