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

Control printing data on report based on criteria

Status
Not open for further replies.

MaggieLeatherman

Programmer
May 9, 2004
59
US
Hi, I have a report where the detail should not print if certain criteria is met... for ex.

If Surv = '3' don't print that record
If Surv = '1' and Cond = "D" or "SD" - print that record
etc....

How do you supress printing on a report based on code.

Thanks, Margaret
 
This is what I use to print. After the click event of the command button:

'Put in message prompt to go directly to the printer.
If (MsgBox("Report Options:" & vbNewLine & _
"Would you like to Print the Report?", vbYesNo) = vbYes) Then
DoCmd.OpenReport stDocName, acNormal

End If

DoCmd.OpenReport stDocName, acPreview

Instead of the MSGBOX, you can replace that with an IIF statement, or a "select case".
 
I haven't tried it but the Detail section of a report has an On Print event which has a Cancel argument... so my thinking is that you could use VBA in that event to evaluate whatever criteria you want to decide the printing and, if that criteria is met, cancel the print using the Cancel argument.

What I don't know, as I haven't tried it, is whether this cancels the whole job or just the 1 Detail line.

In all honesty, you'd be much better off either modifying the report's underlying record source or opening it with a WHERE-type parameter to only include the data you want to print in the first place.
 
When I used the constant "vbNewLine" , I got the following message "Compile Error, Invalid use of property"

Any Idea how to fix this?

Here's my code:
If IsNull(Me.Sur1) And IsNull(Me.Sur2) And IsNull(Me.Sur3) And IsNull(Me.Sur4) And IsNull(Me.Sur5) Then
vbNewLine
End If

Thanks, Maggie
 
Why not use a query, as Remou previously suggested? After all, that's what queries are used for.
 

select surv
case 3
DoCmd.OpenReport stDocName, acNormal
case 1
if Cond = "D" or Cond = "SD" then
DoCmd.OpenReport stDocName, acPreview
end if
end select


Ian Mayor (UK)
Program Error
Programming is 1% coding, 50% error checking and 49% sweat as your application bombs out in front of the client.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top