Results 1 to 6 of 6
  1. #1
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12

    How to do conditional message box based on previous query results in a Macro


    I have a macro that imports data into a file called DownloadData, then runs a query to make sure that the records don't already exist in the Transactions table based on the date. Basically, I'm making sure that the dates in the DownloadData table are greater than the maximum transaction date in the Transactions table. Currently, the query will return no records if the data has not already been transferred. If records exist that are less than or equal to the maximum transaction date, then records get displayed. I was hoping to do a message box in my macro that would give an error message if records do get returned in that query, but return an information message if no records get returned.

    Is there a way to tell the macro that no data was returned and conditionally display either the error message or the informational message?

  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
    22,521
    Try

    Code:
    If DCount("*", "QueryName") > 0 Then
      MsgBox "query has records"
    Else
      MsgBox "no records"
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, just realized you said macro. You should be able to do the same thing in a macro. I don't use them so don't know the specific action names but they are probably similar.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by pbaldy View Post
    Sorry, just realized you said macro. You should be able to do the same thing in a macro. I don't use them so don't know the specific action names but they are probably similar.
    Half the time people say macro when they mean VBA, having come from an Excel background.

    O/P needs to clarify.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12
    I did mean macro, and not VBA. Your advice was enough to send me in the correct direction. Thank you so much for your help.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2019, 07:54 AM
  2. Replies: 15
    Last Post: 09-26-2016, 04:14 PM
  3. Conditional Query with conditional results
    By Jeff_in_KCMO in forum Queries
    Replies: 4
    Last Post: 09-10-2014, 01:44 PM
  4. Replies: 1
    Last Post: 12-17-2013, 01:53 AM
  5. Create Message Box based on query results
    By stanley721 in forum Queries
    Replies: 7
    Last Post: 02-14-2013, 10:04 AM

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