Results 1 to 4 of 4

When a query result is empty.....

  1. #1
    khanson is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    2

    When a query result is empty.....

    Hi, I have been searching the net for an answer but I am not sure of the right question...so I would like to pose it here. I have a simple query that returns data based on entering a specific criteria. The query is run from a macro and the results get created in a spreadsheet and emailed to certain people. The problem I have is that if the query returns no data, for whatever reason, then I don't wish the spreadsheet to be created or emailed. So, in basic terms, if I enter criteria that is spelt incorrectly or the data doesn't exist, I want the query to error and tell me why. Is this something easy to achieve..??

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    12,198
    One way would be to add code to your process that uses DCount to test the query. If greater than 0, continue the process, else abort.
    Paul (wino moderator)
    MS Access MVP
    www.BaldyWeb.com

  3. #3
    khanson is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    2
    OK....not sure where in the query I should be adding code....or even how the code would read...not an Access expert unfortunately...can you give me an example..?

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    12,198
    It would not be in the query, it would be in the macro or VBA code that was doing your process. I don't use macros, but I think you'd use a Condition. In VBA code this type of thing:

    Code:
    If DCount(...) > 0 Then
      'Do your exporting and emailing
    Else
      Msgbox "No records to email"
    End If
    Paul (wino moderator)
    MS Access MVP
    www.BaldyWeb.com

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

Similar Threads

  1. combine query result
    By Fenvy in forum Queries
    Replies: 1
    Last Post: 06-22-2011, 04:02 PM
  2. Update Query on empty fields
    By bryan in forum Access
    Replies: 3
    Last Post: 01-18-2011, 09:36 AM
  3. Replies: 2
    Last Post: 05-18-2010, 12:43 PM
  4. Empty Column in Query
    By sesproul in forum Queries
    Replies: 3
    Last Post: 01-18-2010, 04:04 PM
  5. Controls go blank on empty query result
    By kevdfisch in forum Programming
    Replies: 4
    Last Post: 08-25-2009, 07:07 AM

Posting Permissions

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