Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to limit Subreport detail are to only print 5 records

Status
Not open for further replies.

RonMck

IS-IT--Management
Dec 14, 2001
8
0
0
CA
I have a report that pulls up equiopment info. Within this report, there is a subreport that pulls up all maintenance info for that piece of equipment. There may be up to 100+ records, though I only want to print 5.

The sub report on the main report it linked by the master and child field. (The sub report query does not have a parameter field to limit the records)

I've lopked at the TOP SQL Function, though it doesn't work with what I want.

Basically, just need to have the detail section nof the sub report print 5 of the first records and that is it?

Does anyone have any ideas on how to get the subreport to only print the 5 records?

Any info would be appreciated,

RMc
 
If by "print" you mean "display", then dim a counter in the general declarations, increment it in the detail print event; when the counter > 5, set cancel = true.

All I ask is a chance to prove that money can't make me happy.
 
Thanks for the info, I wasd looking for a more complicated solution.. could be as simple as this.

My only problem now is the Cancel = true.

I have this in the print detail section. It doesn't stop the printing... it loops all through the recordset and prints/displays the 5 records and leaves blanks for the other 10 that may follow.

I need it to quit printing and not have the subreport detail section expand after the 5 records.

Is theer another area to add the cancel=true?

RMc

 
I just answered your same question in the MS Access public news group
You can add a text box to the detail section of the subreport:
Name: txtCount
Control Source: =1
Running Sum: Over Group
Visible: No
Then add code to the On Format event (module window) of this section:
Cancel = (Me.txtCount>5)

Let us know if this doesn't work.

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
Just be careful with OnFormat, as in some instances it will fire twice for the same record.

All I ask is a chance to prove that money can't make me happy.
 
Looks good, tested this and it seems to do the job.

Thank you both,

RMc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top