Avatar of davewalter1
davewalter1
 asked on

How can I use a macro to delete Microsoft Access tables with relationships?

I need to provide a limited view of a database to a few individuals, with only a few tables and queries. My thought was to create a new database, and import the relevant tables into it. I created a macro that runs an import specification, and it works fine.

The problem is refreshing the tables. I want to run a scheduled task for this and, as you probably know, this raises several issues. First, repeatedly running the macro creates multiple copies of the tables and queries.  And deleting the tables before re-running the import routine fails because of relationships between the tables. I don't care about losing the relationships. I want to delete everything and then import the tables again, in just one shot.

I should also say that I've been using Access for a long time, but I don't do anything extremely complicated with it. So my experience is extensive but my skill level is moderate. I use macros because they're easy to use and work for my simple tasks. I don't have much experience with VBA in Access.

Thanks for your help.
DatabasesMicrosoft Access

Avatar of undefined
Last Comment
PatHartman

8/22/2022 - Mon
Fabrice Lambert

Instead of "refreshing tables", what about running 2 queries:
One that will delete existing data.
One that will insert new data.
davewalter1

ASKER
I thought about doing that, and I will if I have to, but I don't want to include those queries in the new database.
PatHartman

Copying the data leaves you in jeopardy of the copy being out of date.  Why would you not just link to the permanent tables?  Also if the forms/reports etc are copies of what already exists in the production database, you have now created a maintenance problem because you (or your successor) have two sets of objects to update.  I would rethink this process.

However, if your heart is set on your present course of action, just remove the RI.  The satellite data should never be updated, so RI isn't necessary.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
davewalter1

ASKER
I'm not concerned about currency, because the data in these tables don't change very frequently, and I'll rebuild every day. There's no maintenance issue, because no one will be writing to this database. I can't remove referential integrity without directly interacting with the database, and I don't want to do that. All I want to do is import a few tables and queries, delete them, import them again, and do this once a day.
ASKER CERTIFIED SOLUTION
PatHartman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
davewalter1

ASKER
Actually, this put me on the right track. Thanks so much! Here's what was happening: I was importing a group of tables in one shot using one import specification. Importing the tables this way retained their relationships. Because they had relationships, I couldn't delete them with a macro. If I import each table individually, they lose their relationships, and I can delete them with a macro.

Thanks again!
PatHartman

You're welcome.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.