Report.NoData 事件 (Access)

NoData 事件發生於 Microsoft Access 格式化 (此報表結合到空的記錄集) 沒有資料,列印報表之後,但是在報表被列印之前。 使用此事件可取消列印空白報表。

語法

運算式NoData (Cancel)

表達 代表 Report 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Cancel 必要 整數 此設定決定是否要列印報表。 將 Cancel 引數設定為 True (1) 會防止列印報表。 您也可以使用 DoCmd 物件的 CancelEvent 方法取消報表的列印。

註解

若要在此事件發生時執行宏或事件程序,請將 OnNoData 屬性設定為宏的名稱或 [事件程序]。

如果報表未使用報表的 RecordSource 屬性) 系結至資料表或查詢 (,則不會發生 NoData 事件。

此事件會發生在報表的 Format 事件之後,但在第一個 Print 事件之前。

子報表不會發生此事件。 如果您想要在子報表沒有資料時隱藏子報表上的控制項,讓控制項在此情況下不會列印,您可以在Format 或Print事件發生時執行的宏或事件程序中使用HasData屬性。

NoData事件會發生在報表的第一個Page事件之前。

範例

下列範例顯示如何在報表沒有資料時取消列印。 也會顯示一個通知使用者列印已取消的訊息方塊。

若要嘗試此範例,請將下列事件程序新增至報表中。 當報表沒有資料時,請嘗試執行報表。

Private Sub Report_NoData(Cancel As Integer) 
    MsgBox "The report has no data." & _ 
         chr(13) & "Printing is canceled. " & _ 
         chr(13) & "Check the data source for the " & _ 
         chr(13) & "report. Make sure you entered " & _ 
         chr(13) & "the correct criteria (for " & _ 
         chr(13) & "example, a valid range of " & _ 
         chr(13) & "dates),." vbOKOnly + vbInformation 
    Cancel = True 
End Sub 

下列範例示範如何使用報表的 NoData 事件,防止報表在沒有顯示任何資料時開啟。

Private Sub Report_NoData(Cancel As Integer)

    'Add code here that will be executed if no data
    'was returned by the Report's RecordSource
    MsgBox "No customers ordered this product this month. " & _
        "The report will now close."
    Cancel = True

End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應