Results 1 to 5 of 5
  1. #1
    dgrimes is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    11

    MessageBox when there IS data returned by a Query

    I need to have a MessageBox display when there is ANY data returned by a specific query. I want my database to open with a macro that checks a specific query, and if there is any data returned at all, show a MessageBox stating that fact. I cannot seem to find any information on this. There is plenty of information on how to complete this when there is NO data. I know this is probably simple code but I just cannot get it to accept.



    Please help!

    Thank you.

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can use the DCOUNT function to count the number of records returned by the query, i.e.
    Code:
    If DCOUNT("*","QueryName") > 0 Then
        MsgBox "There is data in your query!"
    End If
    For more on DCOUNT, see: http://www.techonthenet.com/access/f...ain/dcount.php

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    There is plenty of information on how to complete this when there is NO data. I know this is probably simple code but I just cannot get it to accept.
    If you can find a technique for when there is NO data, you could try putting a "Not" in the set up to do the opposite.

  4. #4
    dgrimes is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    11
    ************************

  5. #5
    dgrimes is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    11
    Quote Originally Posted by JoeM View Post
    You can use the DCOUNT function to count the number of records returned by the query, i.e.
    Code:
    If DCOUNT("*","QueryName") > 0 Then
        MsgBox "There is data in your query!"
    End If
    For more on DCOUNT, see: http://www.techonthenet.com/access/f...ain/dcount.php
    This worked perfectly! I knew it was something simple. Thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send email to persons returned in a query
    By Remillard in forum Programming
    Replies: 2
    Last Post: 04-04-2013, 10:15 AM
  2. Query data not being returned
    By rperrosx in forum Access
    Replies: 3
    Last Post: 12-20-2012, 05:42 PM
  3. Replies: 1
    Last Post: 09-22-2010, 08:03 AM
  4. Replies: 6
    Last Post: 09-25-2009, 12:40 PM
  5. Counting returned records in a query
    By johncob in forum Queries
    Replies: 0
    Last Post: 02-11-2009, 05:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums