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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnPrint Event executes only after all data is formatted

Status
Not open for further replies.

RandyJ

Technical User
Jun 14, 2001
7
US
I have a report that needs to determine a set of criteria for each record prior to printing the detail line.

In the OnFormat event, I test each record in the recordset. If it doesn't meet the criteria, I set the following properties.

With Me
.MoveLayout = False
.NextRecord = True
.PrintSection = False
End With

The problem I'm encountering is the report iterates through the entire recordset before it executes the Detail_Print sub. The only loop I'm using is one that traverses an array to test the current record for qualifying criteria.

When I step through the code and it reaches the End Sub line in the Detail_Format sub, for each record, instead of going to Detail_Print, it moves back to the beginning of Detail_Format. Only when it's reached the EOF marker for the recordset does it then execute Detail_Print.

I have another report that is similar, but it performs the Print_Detail sub for each record in the recordset. I've tried setting the properties for the report that isn't working to match the properties for the report that is working. I've also recreated the report from scratch.

Any suggestions would be greatly appreciated.

Randy Johnston
Best Software, Inc.
 
If you are trying to exclude records from appearing in your report based on certain criteria, the On Format event is the place to do it. Use something like this:
Code:
If ....Your criteria.... Then
Cancel = True
Code:
End If
That will suppress the printing of that record and then evaluate the next.....
 
CosmoKramer,

Thanks for your quick response. I added the line Cancel=True, but even that didn't work. For some reason, it formats the entire report before printing, and I think that is the reason it's losing the formatting options and now the Cancel value. I'm sure I'm doing something wrong, but just haven't been able to figure it out yet.

Thanks again.
 
Did you add the "Cancel=True" line to the code you already had, or did you replace your code with that statement?? I have used that syntax several times before. It definitely does evaluate each record one at a time.......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top