Way to avoid 'halt' in macro

S

SKB

I am running a macro that opens, selects all and copies records from a
query. If there are no records, it halts the macro. Any way to avoid
this? The records are being appended to an existing table if that helps.


SKB
 
S

Steve Schapel

SKB,

First of all, your methodology is probably not the best. This sounds
like the ideal job for an Append Query. It is virtually never a good
idea to try and manipulate data directly within table or query datasheets.

Anyway, to answer your question, you can use a Condition in your macro,
the equivalent of this...
DCount("*","NameOfYourQuery")>0
That way, the macro will only happen if there are records returned, and
thus no Halt message.
 
S

SKB

Steve said:
SKB,

First of all, your methodology is probably not the best. This sounds
like the ideal job for an Append Query. It is virtually never a good
idea to try and manipulate data directly within table or query datasheets.

Anyway, to answer your question, you can use a Condition in your macro,
the equivalent of this...
DCount("*","NameOfYourQuery")>0
That way, the macro will only happen if there are records returned, and
thus no Halt message.
Steve,
So, you are saying, use an append query(s) of a query(s) to update the
table. Meaning it would eliminate the need for the macro in the first place?

SKB
 
S

Steve Schapel

SKB,

Well, yout probably don't need "an append query of a query". Just
change your existing query into an Append Query (select Append from the
Query menu in design view of the query), and then just run this. To run
it manually, click the toolbar button with the red [!] icon. If you
want to automate the process, you can use an OpenQuery action in a
macro, and this will run the append. If you do this, you will probably
want to put a SetWarnings/No action in your macro before the OpenQuery,
to suppress the display of the action query confirmation prompts.
 
S

SKB

Steve said:
SKB,

Well, yout probably don't need "an append query of a query". Just
change your existing query into an Append Query (select Append from the
Query menu in design view of the query), and then just run this.
I did figure that out. As you can tell, I only know enough to be
dangerous. :)

To run
it manually, click the toolbar button with the red [!] icon. If you
want to automate the process, you can use an OpenQuery action in a
macro, and this will run the append. If you do this, you will probably
want to put a SetWarnings/No action in your macro before the OpenQuery,
to suppress the display of the action query confirmation prompts.

I will.

Thank you,
SKB
 

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