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

not print report if null

Status
Not open for further replies.

smiley0q0

Technical User
Feb 27, 2001
356
US
i would like for this to NOT pull the report of the org if it is null. there are some days that one of the orgs have nothing in them and it just has errors across the whole report. How can i make it so it only pulls the reports that are not null. here is my code i am using.

Private Sub cmdPrint3_Click()
Dim x As Integer, I As Integer, c As Integer
Dim strTable As String
Dim strReport As String
Dim db As Database, rc As Recordset

Set db = CurrentDb
Set rc = db.OpenRecordset("tblDates")

c = Me.cboCopy.Value
strTable = "tblDates"
strReport = "rptCycleByGraph"

If IsNull(c) Then
c = 1
End If
Interaction.MsgBox "You are about to print " & c & " copies"
For I = 1 To 3
x = Choose(I, 550, 555, 556)
With rc
.Edit ' Enable editing.
.Fields("ClientOrg") = x
.Update
End With
DoCmd.SelectObject acReport, strReport, True
DoCmd.PrintOut acPrintAll, , , , c

'DoCmd.OpenReport strReport, acViewNormal
'DoCmd.Close acReport, strReport
Next I
End Sub

Thank for your help in advance.

Smiley


 
Try setting the On No Data event for the report to:
Cancel = -1

It looks like this:

Private sub NoData(Cancel as integer)

'Msg saying that there is no data matching this criteria

Cancel = -1

end sub

HTH

Bob
 
can i put this somewhere in the code that i have now?
 
I have done this, but it returns an error (2501) which tells me that I have clicked Cancel on an event. I have just handled this error, but is there some way of writing this up so that no errors are created?

Cheers
Jo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top