How do I do this (if condition)

peskywinnets

Registered User.
Local time
Today, 18:05
Joined
Feb 4, 2014
Messages
578
So I have a large database, at the end of the day I run a macro. the macros runs VBA code & queries. Simples.

What I need is a way of having this macro to check two conditions in a database ('emailed' = false, 'EC' = true) & if there are any rows with these conditions met, then to run some other (extra) queries.

Now I'm aware of the 'If' option in a macro, but how do I use it to check to see if those two conditions are met?
 
you can always put it in a button click
(instead of macro, use EVENT PROCEDURE)

Code:
 sub btnCheck_click()
 if 'emailed' = false and 'EC' = true then docmd.runmacro "mExtraMacro"
 end sub
 
Thanks, but I'm not sure I've explained myself well...I need the macro to automatically hunt through the database to see if there are any rows with those two conditions set & if so then act (by running other additional queries).

One way I'd thought was to have a query to check for those two conditions, but how can I have a macro check whether the query has any results contained within?
 
I don't think you can. I think you will have to use VBA. However you can try this - Create a query that pulls in any records that match your criteria ( 'emailed' = false and 'EC' = true).
In the macro
If DCount("AFieldInYourQuery", "YourQuery") >0 this would mean you have records
Then do whateverelse you want to do
 
I think you will need VBA code. I'm not 100% sure as I don't use macros very much.

Sent from my SM-G925F using Tapatalk
 
I don't think you can. I think you will have to use VBA. However you can try this - Create a query that pulls in any records that match your criteria ( 'emailed' = false and 'EC' = true).
In the macro
If DCount("AFieldInYourQuery", "YourQuery") >0 this would mean you have records
Then do whateverelse you want to do

this is what I was angling at, but didn't know the command to press into action.

I've since deployed a test macro to test the theory, but none of the if conditions are being met (& it must be one of them!), what am I missing...

 
Your second check is inside your first one so will never be reached ...
Try an

ELSE

if you can in a macro
 
Your second check is inside your first one so will never be reached ...
Try an

ELSE

if you can in a macro

that was it (I looked for an else if earlier...but I now see it's tucked way over the RH side of screen) ....many thanks....works a charm :-)
 
I would like to create a macro using Dcount. All I get is syntex error.

Macro begins:

If
=DCount("[ContactId]","qryAppendimportContacts")=0 Then
CancelEvent

I have tried every iteration I can think of, I am following examples I find on the web.. Nothing works.

I have several access book. None of them show how to do this.

I don't know whether to start my function in the macro with = or not.
No examples anywhere.



DCount("[ContactId]","qryAppendimportContacts")=0

=DCount("ContactId","qryAppendimportContacts")=0

=DCount("[ContactId]","qryAppendimportContacts")=0


:banghead:

Please explain how to do this... I don't want my query to run if there are no records.

Thank you.

Hefly
 
I'm not an expert, but you've got several things going on there, when I hit problems like you have I strip it back, therefore in a VBA window, I'd do this...

myTest = DCount("[ContactId]","qryAppendimportContacts")
debug.print myTest

...& see what you have, if you get a number returned then you know that bit is ok & you can build up from there.
 

Users who are viewing this thread

Back
Top Bottom