2014-01-30 24 views
2

我在打開報告的表單上有一個按鈕。這份報告,因爲它應該每當有數據開放然而,當有在報告中,我得到一個錯誤,沒有數據和調試帶我到這條線
DoCmd.OpenReport "FilesToBeReturnedReport", acViewReport, "", "", acNormalDoCmd.OpenReport的問題

這裏是整個代碼:

`With Me 
    If ((IsNull(.StartDate) Or .EndDate = "")) Then 
     Beep 
     MsgBox "You must enter report start period", vbOKOnly, "Required Data!" 
    ElseIf (IsNull(.EndDate) Or .EndDate = "") Then 
     Beep 
     MsgBox "You must enter report end date", vbOKOnly, "Reqired Data" 
    ElseIf (.StartDate > .EndDate) Then 
     Beep 
     MsgBox "The report start date must be earlier than the end date", vbOKOnly, "Required Data" 
    Else 
     DoCmd.OpenReport "FilesToBeReturnedReport", acViewReport, "", "", acNormal 
    End If 
End With` 

我需要在明天之前完成此任何幫助,我們將非常感謝。由於

回答

-1

我並不是真的非常使用VBA經歷了訪問,但爲什麼不試試puttting

DoCmd.OpenReport 「FilesToBeReturnedReport」,acViewReport, 「」, 「」,acNormal

End with 
+0

我只是想你的建議,但沒有奏效。我所做的就是使用'On Load'事件過程來運行記錄的計數,並關閉if = 0並向用戶返回消息。儘管如此,感謝您的努力。 – Kefash

+0

對不起,很高興你能解決它@kefash – Dre488

2

訪問報告有一個NoData事件。在沒有數據的情況下,您可以放置​​想要運行的操作。如果在NoData事件中將取消設置爲True,則報告將不會打開或打印。如果您將「取消」作爲其默認False,則報告將按照現在的樣子打開。

這就是說,你還需要抓住這個錯誤使用DoCmd.OpenReport時:

On Error Goto ReportFail 
DoCmd.OpenReport strReport, acViewPreview 

ExitHere: 
Exit Sub 

ReportFail: 
If Err=2501 Then 
    'OpenReport was canceled 
    Err.Clear 
    Resume ExitHere 
Else 
    MsgBox Err.Number & ": " & Err.Description 
End If 
End Sub 
+1

是大部分正確的,除了Err號碼應該是2501。 –