Cancel Macro If Table is empty.

R

Ron

In a Macro, I want to check if a specified table is empty. When it's empty, I
want to Cancel a Macro from running.

Another situation:
A Table containing Data with a Yes/No field to represent Open/Closed Projects.
I want to cancel a specific Macro if ALL the records are Closed.
i.e. If running a query to display all open Items, No Data is Returned...
 
S

Steve Schapel

Ron,

Use the Condition of the macro action for this.

In the first scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable")>0

In the second scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable","[YourYesNoField]<>0")>0
 
R

Ron

Thank You Steve... Just what I was looking for...
Ron

Steve Schapel said:
Ron,

Use the Condition of the macro action for this.

In the first scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable")>0

In the second scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable","[YourYesNoField]<>0")>0

--

Steve Schapel, Microsoft Access MVP


Ron said:
In a Macro, I want to check if a specified table is empty. When it's
empty, I
want to Cancel a Macro from running.

Another situation:
A Table containing Data with a Yes/No field to represent Open/Closed
Projects.
I want to cancel a specific Macro if ALL the records are Closed.
i.e. If running a query to display all open Items, No Data is Returned...
 
R

Ron

Steve,

I have one more scenario I'd like help with,
A Monthly Data Table containing a field Named [Balance].

I want to cancel a specific Macro if the Sum of [Balance] = 0

I tried this statement, but it does not work:
DCount("*","Transactions-New","Sum([Balance])")=0

Ron

Steve Schapel said:
Ron,

Use the Condition of the macro action for this.

In the first scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable")>0

In the second scenario, the Condition the equivalent of:
DCount("*","NameOfYOurTable","[YourYesNoField]<>0")>0

--

Steve Schapel, Microsoft Access MVP


Ron said:
In a Macro, I want to check if a specified table is empty. When it's
empty, I
want to Cancel a Macro from running.

Another situation:
A Table containing Data with a Yes/No field to represent Open/Closed
Projects.
I want to cancel a specific Macro if ALL the records are Closed.
i.e. If running a query to display all open Items, No Data is Returned...
 
S

Steve Schapel

Ron,

Instead of thinking about "cancelling" the macro, think of it in terms of
the condition under which you will run it. That's closer to the concept of
how Conditions in macros work.

So you want the macro to run if the Sum of the balance field is more than 0.
Right?

DSum("[Balance]","Transactions-New")>0
 
R

Ron

Thanks Steve. Excellent suggestion.
I'll try your approach.
I think if I go this way, I'd put the Statement in a new Macro.

DSum("[Balance]","Transactions-New")>0
Action = RunMacro
Name = mcrTransferData <== Contains about 8 Actions

If Result Sum Balance = 0, then mcrTransferData fails to run...

I really have trouble with MS Help in Office 2007 in finding examples of any
Coding.
I appreciate your expertise in this area...

Ron


Steve Schapel said:
Ron,

Instead of thinking about "cancelling" the macro, think of it in terms of
the condition under which you will run it. That's closer to the concept of
how Conditions in macros work.

So you want the macro to run if the Sum of the balance field is more than 0.
Right?

DSum("[Balance]","Transactions-New")>0

--

Steve Schapel, Microsoft Access MVP


Ron said:
Steve,

I have one more scenario I'd like help with,
A Monthly Data Table containing a field Named [Balance].

I want to cancel a specific Macro if the Sum of [Balance] = 0

I tried this statement, but it does not work:
DCount("*","Transactions-New","Sum([Balance])")=0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top