Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reports with No Data (2000)

    I can't wait until the search feature is back up! I'm sure this question has been asked before but I haven't found it in the limited archive searching I've done...

    I have created a form so that my users can run their own reports. If there is no data found in the query I want a MsgBox to pop up that says "Your results produced no data" How can I do this? Do I have to write code for the form or the report?

    Thanks!

    Kindra

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reports with No Data (2000)

    Open the report in design view.
    Activate the Events tab in the Properties window.
    Click in the On No Data event.
    Select Event Procedure from the dropdown list.
    Click the Builder button (the three dots to the right).
    Write code like the following:

    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "Your results produced no data.", vbInformation
    Cancel = True
    End Sub

    Save the report design.
    If you open the report from a form using DoCmd.OpenReport, you will get an error message if the report is canceled because there are no data. You get around this by ignoring error # 2501 (action canceled). For example in the On Click event of a command button:

    Private Sub cmdReport_Click
    On Error GoTo ErrHandler

    DoCmd.OpenReport "rptMyReport", acViewPreview
    Exit Sub

    ErrHandler:
    If Err <> 2501 Then
    ' Only display error message if not 2501.
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reports with No Data (2000)

    Thank you Hans!!! Works perfectly.

Posting Permissions

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