Macro: if 'query returns no records'... (1 Viewer)

XelaIrodavlas

Registered User.
Local time
Today, 00:07
Joined
Oct 26, 2012
Messages
174
Hi all,

I have created a macro which emails the results of a query to myself when I open the access database.

- However, I only want it to do this if the query finds any records, otherwise it sends me a blank document half the time.

- I have tried using the 'If' Program Flow so it either sends the email, or just makes a popup to say no results found. But I don't know how to instruct Access to know whether the Query found any records or not, so you see the missing piece of the puzzle.

So the issue is in the If function, so far all I have is:
If [TheQuery]![QuerysUniqueID]="" then...

- but this doesn't work. I need it to say 'if the query finds no records...'

Please note I'm an access noobie using the macro creator not VBA (I have a vague understanding of it...), so use simple words please :)

Thanks in advance,
 

pr2-eugin

Super Moderator
Local time
Today, 00:07
Joined
Nov 30, 2011
Messages
8,494
Have you considered using a DCount as a checking condition before calling the procedure? I am not great with Macros.. but should be simple like..
Code:
If DCount("*","yourQueryName") > 0 Then
    Call the function
Else
    Msgbox("No details to send")
End If


Could you delete the other thread, if this is what you wanted and if this has solved your problem?
 

Attachments

  • macro.png
    macro.png
    8.8 KB · Views: 17,802
Last edited:

XelaIrodavlas

Registered User.
Local time
Today, 00:07
Joined
Oct 26, 2012
Messages
174
You are fast becoming my favorite Tecchy :) this works perfectly thank you very much.
I have deleted the other thread.
 

pr2-eugin

Super Moderator
Local time
Today, 00:07
Joined
Nov 30, 2011
Messages
8,494
Thanks for the comment.. Appreciate it.. But I am just like you trying to learn and helping others with what I could.. Glad to do it.. :)
 

dsm787

New member
Local time
Yesterday, 18:07
Joined
Jun 22, 2015
Messages
1
I have used this solution, but am getting the error "cannot find the name 'queryname' you entered in the expression. You may have specified a control that wasn't on the current object without specifying the correct form or report context."
 

Users who are viewing this thread

Top Bottom