Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2009
    Posts
    4

    Message to appear if no records found

    Hi All,

    I've managed to get a working database, including the count function to display the number of records found, but I just need a message to show up when no records are found.

    So what I have is a form with a series of combo boxes which link to a query. Once the values have been filled, the Search button takes the user to another form which displays results.

    But what I need is that once the Search button is clicked, if there are no records, a message to appear (could be another form?) to say there are no records and to give the user another go (ie. back to the Search form)

    Any help would be greatly appreciated.

    Many thanks
    Simon

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,794
    Try

    Code:
    If DCount("*", "QueryName") = 0 Then
      Msgbox "No records found"
    Else
      DoCmd.OpenForm...
    End If
    Paul

  3. #3
    Join Date
    Mar 2009
    Posts
    4

    Thumbs up Thank you!

    Many thanks Paul, that worked a treat!!

  4. #4
    Join Date
    Mar 2009
    Posts
    3
    could you please explain how and where you put the code into access i have tried many times using a macro, putting into the on load option of the form and i continually keep gettting error messages.

    can anyone tell me where i am going wrong?

    thanks

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,794
    In the situation described in this thread, that code would be behind a command button.
    Paul

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,448
    just wondering if an Access form has the similar nodata property to a report, so you could insert your message in the forms on load/open event assuming you are opening a new form each time with your macros.
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,794
    To my knowledge, no (A2k anyway). Forms have a HasData property, but it can only be read while printing or in print preview, so it doesn't really help in this situation.
    Paul

  8. #8
    Join Date
    Mar 2009
    Posts
    4

    Access 07 Problem

    Hi pbaldy,

    The code worked fine in Access 03, but having tried it in 07, it doesn't work. Any ideas why not?

    Thanks

  9. #9
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,794
    There's nothing there that wouldn't work in 2007. Is the db in a trusted location so that code runs (or has code been enabled via the option in the toolbar)?
    Paul

  10. #10
    Join Date
    Mar 2009
    Posts
    4

    Thanks...

    yeah, got it working now. I think it must have been those stupid security settings on Access that prevent anything working properly!

    Thanks once again for your help

  11. #11
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,794
    No problemo; glad we got it sorted out.
    Paul

Posting Permissions

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