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

stop blank report from printing 2

Status
Not open for further replies.

lora

Programmer
Dec 1, 1999
43
US
any ideas on how to stop a blank report from printing? <br>
<br>
i am going through a table and printing a set of reports for each record. is there any code i can use to check whether the report is blank and skip printing if it is?<br>
<br>
this is the code i'm using<br>
<br>
Sub RegionVPReports()<br>
<br>
Dim dbs As Database<br>
Dim rstName As Recordset<br>
<br>
Set dbs = CurrentDb<br>
Set rstName = dbs.OpenRecordset(&quot;RegionT&quot;)<br>
<br>
Do Until rstName.EOF<br>
<br>
DoCmd.OpenReport &quot;TM Summary&quot;, , , &quot;tmt.REGION='&quot; & rstName!Region & &quot;'&quot;<br>
.<br>
.<br>
.<br>
<br>
rstName.MoveNext<br>
Loop<br>
<br>
rstName.Close<br>
<br>
End Sub<br>
<br>
Thanks<br>
<br>

 
Well lets see in your code you need an IF statement<br>
Can you check a field to see if it is blank like the example below<br>
<br>
Do Until rstName.EOF<br>
'Check to see if record is blank<br>
If IsNull(rstName.Fields(&quot;Somefield&quot;)) Then<br>
'do nothing<br>
Else<br>
'Print the report<br>
DoCmd.OpenReport &quot;TM Summary&quot;, , , &quot;tmt.REGION='&quot; & rstName!Region & &quot;'&quot;<br>
End If<br>
<br>
rstName.MoveNext<br>
Loop<br>
<br>
rstName.Close<br>

 
Try the NoData event procedure of report. You can prevents the report from printing by setting Cancel as True in the procedure.<br>
<br>
The following example is from Access97 Help topic &quot;NoData Event — Event Procedures.&quot; I hope it helps.<br>
<br>
<br>
Private Sub Report_NoData(Cancel As Integer)<br>
MsgBox &quot;The report has no data.&quot; _<br>
& &quot;@Printing the report is canceled. &quot; _<br>
& &quot;@Check the source of data for the report to make sure you &quot; _<br>
& &quot;entered the correct criteria (for example, a valid range &quot; _<br>
& &quot;of dates).&quot;, vbOKOnly + vbInformation<br>
Cancel = True<br>
End Sub
 
Hi everyone,

I have a similar problem. I have a form with several selection criteria . When I hit the open report button,I want it to NOT open the report if there is no data. When I try the Cancel=True that Seaport suggested, I get an error &quot; The Open Report Action was cancelled&quot;

I know it is because I am using an open report command and then cancelling it but that is kind of what i want to do. Any ideas to get around this?

Thanks,
ZaZa
 
I've used this in my report open and it worked out...

If DCount(&quot;*&quot;, Me.RecordSource, sWhere) = 0 Then
Cancel = True
MsgBox (&quot;No values for this date - aborting&quot;)
DoCmd.Restore
Exit Sub
End If

I don't profess this to be as good as using the NoData event, but since I can't imagine why it's not working for you, here's another slant. :-Q &quot;Outside of a dog, a book is probably man's best friend; and inside of a dog, it's too dark to read&quot; - G. Marx
 
Thanks for your help Gates

A little while back I thought up of a soultion pretty close to what you have. But I didn't use the Docmd.restore part of your code.

I will insert it and see what it brings to the party.
Thanks for respoonding,

ZaZa

 
Is it not possible to insert this code right before the Do Until?

If rstName.recordcount = 0 then
Msgbox &quot;Sorry, no data!&quot;
exit sub
end if

Jenny

 
You know, I had the same @#$%ing problem and I truly don't know when or how it went away, all I know is that it's not there now!! AAR Some suggest that you work around it with this in your &quot;on error&quot; code:

If Err.Number <> 2501 Then MsgBox Err.Number & &quot;: &quot; & Err.Description
(else resume next, or exit sub) &quot;Outside of a dog, a book is probably man's best friend; and inside of a dog, it's too dark to read&quot; - G. Marx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top