Access 2000, in a Macro I need to find out if a table is empty. HO

G

Guest

Can someone tell me how to use a macro to check if a table, which is just
open, is empty so that actions can be take: 1) if empty... 2) is not empty.

Thanks
 
N

Nikos Yannacopoulos

Nevio,

An easy way is a DCount("*","TableName"). It will return 0 if empty(no
records), a positive integer otherwise.

HTH,
Nikos
 
G

Guest

Nikos,

Thanks, but I need a bit more info:
1) In my Macro do I use the "RunCode" Action with the Function
DCount("*',MYTABLE")?
2) Where and how do I check the interger for the 0 or positive value?

Thank for your help so far,

Nevio
 
N

Nikos Yannacopoulos

While in query design, go View > Conditions to make the Conditions
column visible (unless already visible). In this column, you enter a
condition for Access to evaluate, and the action next to it is executed
only if the condition evaluates to True. If you enter a condition in a
row, all subsequent rows with ... (three dots) in the conditions column
will only be executed if the condition above is true, so the ... symbol
actually extends the condition to subsequent rows. So, to do what you want:

The condition you need is:
DCount("*","TableName") = 0

Put the first action to execute if empty next to it, and ... in all
subsequent rows for actions to execute if empty; add a last one with a
StopMacro action. Then, add the actions to execute if not empty, without
any condition. The result is that if empty the first set executes then
the macro stops, otherwise the first set is skipped and the second
(unconditional) set executes.

HTH,
Nikos
 

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