Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    California, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Returning No Results from query (Acc97)

    Hello again,
    Is there a way to get a query to return a message if the parameter criteria in the query have no matches? If there are no hits the query just displays a blank line, which is ok, but I have reports based on the queries that then have beautiful #error messages in them.

    I've looked in the help but I'm afraid I'm not sure of the correct terminology to look under.

    Thanks.

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Returning No Results from query (Acc97)

    Well, you can add some code to the report:
    <pre>Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There is no data to print. The report will close automatically.", _
    vbOKOnly + vbInformation, "No Data"
    Cancel = True
    End Sub
    </pre>


    This will display a messagebox and then close the report when you click the OK button.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Returning No Results from query (Acc97)

    Be sure to remember to check for error 2501 and ignore this error message on calling the OpenReport else you will get another dialogue box telling you that you have just cancelled a function.
    HTH
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Returning No Results from query (Acc97)

    <img src=/S/doh.gif border=0 alt=doh width=15 height=15>Good point.

    One that I always forget, until someone calls and complains about it. <img src=/S/smash.gif border=0 alt=smash width=30 height=26>
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

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