*** จะทำอย่างไรถ้าต้องการให้ Report ปิดตัวเองไป ถ้าไม่พบข้อมูลใดๆ ***

ในบางคราวเราต้องการไม่ให้ Report แสดงหน้าจอว่างๆขึ้นมาในกรณีที่ไม่พบข้อมูลเลย
เราสามารถทำได้โดยใช้ Event On NoData เขียน Code ดังต่อไปนี้

'************* Code Start *************

Private Sub Report_NoData(Cancel As Integer)
     MsgBox "ไม่พบข้อมูลใดๆเลย" Cancel = True
End Sub

'************* Code End *************

********* Report จะปิดเองอัตโนมัติ แต่ว่าถ้าเป็นการเปิด Report ขณะอยู่บน Form (เปิดโดยปุ่ม) จำเป็นจะต้องดัก Error ดังนี้

*********** Code Start ************

Private Sub CmdOpenReport_Click()
     On Error Resume Next
     DoCmd.OpenReport "SomeReport", acViewPreview
     If Err = 2501 Then Err.Clear
End Sub

'*********** Code End ************