Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Unanswered: Report : On No Data

    Hello,

    I have a report "Overdue" which for most of the day has some data (it runs a query).
    However by the end of the day it should be empty. So, rather that display a report with no data, I would like it to display another report "Overdue Null" which has some other things on - including a nice graphic.

    I can use the "On No Data" event to call the second report, but I can't get it to not display the first.

    I've tried using a macro, but a macro cannot close the report which called it.

    Any ideas?

    James
    Thank you,
    James

  2. #2
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Re: Report : On No Data

    I've solved the problem when using an MDB (by merely inlcuding "Cancel=True", however when I make an MDE I get an error - :
    "The OpenReport action was cancelled".

    My code is :

    Private Sub Report_NoData(Cancel As Integer)
    Cancel = True
    DoCmd.OpenReport ("Overdue Report - Null"), acViewPreview
    End Sub
    Thank you,
    James

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try this:

    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
    End Sub
    '************* Code End *************
    will automatically close the report if there are no records in the underlying source.
    However, if you're opening the report from code behind a form, you need to handle the error that's generated as a result.
    '*********** Code Start ************
    Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
    End Sub
    '*********** Code End ************

  4. #4
    Join Date
    Oct 2003
    Location
    São Paulo - Brazil
    Posts
    91
    Originally posted by hammbakka
    Try this:

    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
    End Sub
    '************* Code End *************
    will automatically close the report if there are no records in the underlying source.
    However, if you're opening the report from code behind a form, you need to handle the error that's generated as a result.
    '*********** Code Start ************
    Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
    End Sub
    '*********** Code End ************
    Where can I find a list of errors numbers ?
    My environment: Windows XP/ Access 2000 - Using Microsoft DAO 3.6 Library

  5. #5
    Join Date
    Jan 2004
    Posts
    1
    Originally posted by hammbakka
    Try this:

    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
    End Sub
    '************* Code End *************
    will automatically close the report if there are no records in the underlying source.
    However, if you're opening the report from code behind a form, you need to handle the error that's generated as a result.
    '*********** Code Start ************
    Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
    End Sub
    '*********** Code End ************
    Hi all,
    I too am having the same problem. I tried to catch the error, but the compiler is not getting past the line of code that calls the open report command: DoCmd.OpenReport stDocName, acPreview

    After it throws the error, it asks do you want to debug? I hit yes, and the DOCmd line is highlighted. I don't think its reading the conditioinal testing.

    Here is my code:
    DoCmd.OpenReport stDocName, acPreview
    If Err = 2501 Then Err.Clear


    Exit_cmdPreview_Click:

    Exit Sub

    Err_cmdPreview_Click:

    If Err.Number = 2501 Then
    'Trap specific error for No Data Event
    Resume Exit_cmdPreview_Click
    Else
    MsgBox Err.Description
    Resume Exit_cmdPreview_Click
    End If
    End Sub

    Any ideas?
    All suggestions welcome.
    Thanks,
    rwiethorn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •