Cancelling On Close Event If There Is No Data

M

Mac

Dear All,

I have a report that runs perfectly except if there is no data, I have
a piece of code in the No Data event:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There Are No cheques To Be Issued At This Time",
vbExclamation, "No Cheques To Raise"
Cancel = True
End Sub

The problem is that the report still runs some code I have for the On
Close event:

Update = MsgBox("Do You Wish To Record The Date Of The Cheque
Request", vbYesNo, "PCT Update Requestor")
If Update = vbYes Then
SetWarnings = False
DoCmd.OpenQuery "Cheque Request - PCT 10 Update",
acViewNormal, acEdit
DoCmd.OpenQuery "Cheque Request - PCT 75 Update",
acViewDesign, acEdit
SetWarnings = True
Else
Exit Sub
End If
End Sub

Is there a way to instruct the report to ignore the on close code if
there is no data?
Thanks in advance.

Andy
 
A

Allen Browne

The report's HasData property is False if it has no data, so how about:

If Me.HasData Then
'put your code in here
End If
 
M

Mac

Sorry Allen,

I'm not with you, where would I place the if statement you suggested? i
also now have the added problem of tryingh to specify printer settings
from with the on close event for a report that would print cover
letters. Any assistance gratefully received.

Regards

Andy

Private Sub Report_Close()
Update = MsgBox("Do You Wish To Record The Date Of The Cheque
Request", vbYesNo, "PCT Update Requestor")
If Update = vbYes Then
SetWarnings = False
DoCmd.OpenReport "Cheque Request - Cover Letter",
acViewNormal, , , acHidden
DoCmd.OpenQuery "Cheque Request - PCT 10 Update",
acViewNormal, acEdit
DoCmd.OpenQuery "Cheque Request - PCT 75 Update",
acViewNormal, acEdit
SetWarnings = True
Else
Exit Sub
End If
End Sub
 
A

Allen Browne

Try testing the report's HasData property inside the report's Close event
procedure.

The If line will be the first one inside the Sub.
The End If will be the last line before End Sub.

For suggestions on the printer issue, see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html
The article is for Access 2002 and 2003, but contains other links for Access
97 and 2000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top