none
NoData event fires, but there is data!? RRS feed

  • Question

  • Hi

    I have a report with a NoData event. The Report opens, with data and the MsgBox NoData too.

    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

    I have debuged the code.
    I have ran Compact and Repair

    O365 32 bit



    Cheers // Peter Forss Stockholm

    Friday, September 6, 2019 1:15 PM

Answers

  • Hi guys

    I am so sorry. The push button opens two reports. And of coarse, in this case, one of them is without data. I feel a bit stupid right now. So sorry I took your time. Really.

    Cheers // Peter Forss Stockholm

    • Marked as answer by ForssPeterNova Saturday, September 7, 2019 4:28 AM
    Saturday, September 7, 2019 4:28 AM

All replies

  • If you open the underlying table/query for the report you have records?

    Daniel Pineault, 2010-2019 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Friday, September 6, 2019 1:28 PM
  • How about a subreport?
    Friday, September 6, 2019 1:52 PM
  • Hi Daniel

    The report is based on a query.

    If I run the query it self, there is records.
    If I open the report I have records AND the NoData.

    If I run a copy of the FE database I have records but not the NoData.

    So .... the report went corrupt. But how and why?

    I deleted the report and then imported it from the database without the NoData issue.
    The error occurs again!


    Cheers // Peter Forss Stockholm


    Friday, September 6, 2019 8:01 PM
  • Hi John

    Why a Sub?


    Cheers // Peter Forss Stockholm

    Friday, September 6, 2019 8:02 PM
  • The report is based on a query.

    If I run the query it self, there is records.
    If I open the report I have records AND the NoData.

    If I run a copy of the FE database I have records but not the NoData.

    So .... the report went corrupt. But how and why?

    I don't think we know yet if the report is corrupt.  Do you by any change assign or modify the report's RecordSource property on the fly, in one of the report's events?  Or, if that property is a stored query, do you change the SQL of the query?

    Is there some code that explicitly calls the Report_NoData() procedure?  I ask because it sets the Cancel argument to True, so if it was being triggered naturally, I'd expect the report's opening to be canceled.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, September 6, 2019 8:14 PM
  • Hi Dirk

    The RecordSource is a stored query.

    Below is all lines of code bound to the report.

    Option Compare Database
    Option Explicit

    Private Sub Report_Close()
        On Error GoTo Report_Close_Error
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
        
        On Error GoTo 0
        Exit Sub

    Report_Close_Error:

        MsgBox "Error " & Err.Number & " (" & Err.description & ") in procedure Report_Close, line " & Erl & "."

    End Sub

    Private Sub Report_Load()
        On Error GoTo Report_Load_Error
    DoCmd.ShowToolbar "Ribbon", acToolbarYes
        
        On Error GoTo 0
        Exit Sub

    Report_Load_Error:

        MsgBox "Error " & Err.Number & " (" & Err.description & ") in procedure Report_Load, line " & Erl & "."

    End Sub

    Private Sub Report_Open(Cancel As Integer)

        On Error GoTo Report_Open_Error
    10   Me!CostOfLoss.Format = Forms![ALLA VAL]![AllaValCurrency].Column(1)
    20   Me![currcost/liter].Format = Forms![ALLA VAL]![AllaValCurrency].Column(1)
    30   Me!AccessTotalsCostOfLoss.Format = Forms![ALLA VAL]![AllaValCurrency].Column(1)

        On Error GoTo 0
        Exit Sub

    Report_Open_Error:

        MsgBox "Error " & Err.Number & " (" & Err.description & ") in procedure Report_Open, line " & Erl & "."

    End Sub
    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


    Cheers // Peter Forss Stockholm

    Friday, September 6, 2019 8:31 PM
  • Hi guys

    I am so sorry. The push button opens two reports. And of coarse, in this case, one of them is without data. I feel a bit stupid right now. So sorry I took your time. Really.

    Cheers // Peter Forss Stockholm

    • Marked as answer by ForssPeterNova Saturday, September 7, 2019 4:28 AM
    Saturday, September 7, 2019 4:28 AM
  • You need to have a report to get the NoData event triggered...my suggestion was right in that concept...but it would impossible to guess that you opening more than 1 report
    Saturday, September 7, 2019 11:29 AM
  • Happens to all of us sooner or later ... you are forgiven

    peter n roth - http://PNR1.com, Maybe some useful stuff

    Saturday, September 7, 2019 9:40 PM