Condition If Table Exists...

  • Thread starter Brian via AccessMonster.com
  • Start date
B

Brian via AccessMonster.com

I have a macro that deletes two tables (created by queries) when a form is
opened. The form's inputs then run queries that re-create those tables.
The problem is when the form is opened and closed, the tables are deleted.
Then when the form opens again the tables aren't there for it to delete and
the macro fails. I thought a conditional statement would fix this, but I
don't know how.
 
K

Ken Snell [MVP]

You can do this "test" via VBA code, but not directly via a macro. You could
call a VBA function from a macro as part of a condition expression.

But why not avoid the problem entirely by replacing the "make table" queries
with "append" queries, and change from deletion of the tables to running
"delete" queries to empty the tables of data.
 
B

Brian via AccessMonster.com

Thanks.

How would I go about making append and delete queries?
 
K

Ken Snell [MVP]

Create a standard select query in design view. Then click on "Query Type"
icon on toolbar and select the query type you want. You'll need to provide a
bit more info as the wizard asks.
 
S

Steve Schapel

Brian,

A agree with Ken's suggestion. However, for the record, you can use a
Condition in your macro with the DLookup() function. For example, a
Condition like this:
DLookup("[YourField]","YourTable")
.... will cause the macro action to not run if YourTable doesn't exist.
 
K

Ken Snell [MVP]

ahhhh... neat trick, Steve!

--

Ken Snell
<MS ACCESS MVP>

Steve Schapel said:
Brian,

A agree with Ken's suggestion. However, for the record, you can use a
Condition in your macro with the DLookup() function. For example, a
Condition like this:
DLookup("[YourField]","YourTable")
... will cause the macro action to not run if YourTable doesn't exist.

--
Steve Schapel, Microsoft Access MVP

I have a macro that deletes two tables (created by queries) when a form
is
opened. The form's inputs then run queries that re-create those tables.
The problem is when the form is opened and closed, the tables are
deleted.
Then when the form opens again the tables aren't there for it to delete
and
the macro fails. I thought a conditional statement would fix this, but I
don't know how.
 

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