Need to skip open OnNoData

B

Bonnie A

Hi everyone! Using A02 on XP. I have a print form that opens a number of
reports (letters, forms, etc.). Sometimes I only have data that opens the
forms and not the letter. I've used the OnNoData event to display a message
"There is no data for the letter" and there is also the fun little "Open
Report Action Cancelled" dialog box that also appears when you click OK on
the OnNoData message.

How can I have neither occur? Just open the forms and not the letter with
no additional clicks. Removing both causes the letter to open with #Error#
written all over it in every field.

I tried this to trap the error in the OnError event but it doesn't work.
Maybe it's too old? Not sure.

MsgBox "Error#: " & DataErr
Response = acDataErrDisplay

When I was trying to type the above, my cursor kept jumping around. I've
rebooted my PC but maybe I'm typing old commands or something?

I also tried to skip the error message with Select Case but I'm missing
something.

I'm pretty sure the error number is 2501 but don't know how to verify it.

Can someone help? I would really appreciate any assistance. Thanks in
advance for your time.
 
S

Stefan Hoffmann

hi Bonnie,

Bonnie said:
I also tried to skip the error message with Select Case but I'm missing
something.

I'm pretty sure the error number is 2501 but don't know how to verify it.
I'm using this instead of a special coded event:

Public Function ReportNoData(AReport As Access.Report)
' On No Data = ReportNoData([Report]).

On Local Error Resume Next

Dim ReportCaptionName As String

ReportCaptionName = AReport.Caption
If ReportCaptionName = "" Then ReportCaptionName = AReport.Name

MsgBox "No data for " & ReportCaptionName, _
vbInformation + vbOKOnly, MSGBOX_CAPTION
DoCmd.CancelEvent

End Function

and

Public Function ReportOpen(AReportName As String, _
Optional AView As AcView = acPreview, _
Optional AFilterName As String = "", _
Optional AWhereCondition As String = "", _
Optional AWindowMode As Access.AcWindowMode
= acWindowNormal _
) As Boolean

On Local Error Resume Next

If CurrentProject.AllReports.Item(AReportName).IsLoaded Then
DoCmd.Close acReport, AReportName
End If

On Local Error GoTo LocalError

DoCmd.OpenReport AReportName, AView, AFilterName, _
AWhereCondition, AWindowMode

' On Local Error Resume Next
' Reports(AReportName).ZoomControl = 100 ' normal size
' Reports(AReportName).ZoomControl = 0 ' fit into window

ReportOpen = True

Exit Function

LocalError:
If Err.Number <> 2501 Then ' ReportNoData Fehler
'error message
End If
ReportOpen = False

End Function


mfG
--> stefan <--
 

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

Similar Threads


Top