PC Review


Reply
Thread Tools Rate Thread

Cancel Macro If Table is empty.

 
 
Ron
Guest
Posts: n/a
 
      5th Mar 2009
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...


 
Reply With Quote
 
 
 
 
Steve Schapel
Guest
Posts: n/a
 
      5th Mar 2009
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" <(E-Mail Removed)> wrote in message
news:867FB1BF-E7B1-4122-81F7-(E-Mail Removed)...
> 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...
>
>

 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      6th Mar 2009
Thank You Steve... Just what I was looking for...
Ron

"Steve Schapel" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:867FB1BF-E7B1-4122-81F7-(E-Mail Removed)...
> > 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...
> >
> >

>

 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      7th Mar 2009
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" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:867FB1BF-E7B1-4122-81F7-(E-Mail Removed)...
> > 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...
> >
> >

>

 
Reply With Quote
 
Steve Schapel
Guest
Posts: n/a
 
      7th Mar 2009
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" <(E-Mail Removed)> wrote in message
news:1145C0AD-35E0-4091-AF0B-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      8th Mar 2009
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" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:1145C0AD-35E0-4091-AF0B-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
in macro how to determine a table is empty or number of records=0 =?Utf-8?B?Y2hvaWdhcnk=?= Microsoft Access Macros 2 8th May 2007 05:11 AM
Access 2000, in a Macro I need to find out if a table is empty. HO =?Utf-8?B?TmV2aW8=?= Microsoft Access Macros 8 6th Jul 2005 10:26 AM
Cancel Macro is user selects 'cancel' at save menu =?Utf-8?B?TWFyaw==?= Microsoft Excel Programming 1 6th Apr 2005 05:45 PM
Need macro to stop if table is empty =?Utf-8?B?QnJlbnQgU3dlZXQ=?= Microsoft Access VBA Modules 4 18th Feb 2005 06:11 PM
Condition in macro to check empty\null fields in a table in Access =?Utf-8?B?QW5lc2g=?= Microsoft Access 1 2nd Dec 2004 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 AM.