On No Data

  • Thread starter Thread starter Becca
  • Start date Start date
B

Becca

Form1 has command button to open Form2 where the user
makes a selection.

Form2, with selection made, has command button to preview
report.

How do I inhibit the preview where no data exists? My
report's OnNoData event has "cancel=true", thus I get a
message that the open event is cancelled.

Help me? Thanks.
Becca




'*********************************************************
Private Sub btnStatement_Click()
On Error GoTo Err_btnStatement_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptClientStatement"
stLinkCriteria = "[ClientID]=" & "'" & Me![ClientID] & "'"

DoCmd.OpenReport stDocName,acViewPreview, ,stLinkCriteria
DoCmd.RunCommand acCmdFitToWindow

Exit_btnStatement_Click:
Exit Sub

Err_btnStatement_Click:
MsgBox Err.Description
Resume Exit_btnStatement_Click

End Sub
'*********************************************************
 
Becca said:
Form1 has command button to open Form2 where the user
makes a selection.

Form2, with selection made, has command button to preview
report.

How do I inhibit the preview where no data exists? My
report's OnNoData event has "cancel=true", thus I get a
message that the open event is cancelled.

Help me? Thanks.


In your Error Handler test to see if the Err.Number = 2501 and ignore if it
is.
 
This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 
Back
Top