• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 42
  • Last Modified:

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.
0
davewalter1
Asked:
davewalter1
  • 3
  • 3
1 Solution
 
Fabrice LambertFabrice LambertCommented:
Instead of "refreshing tables", what about running 2 queries:
One that will delete existing data.
One that will insert new data.
0
 
davewalter1Author Commented:
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.
0
 
PatHartmanCommented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
davewalter1Author Commented:
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.
0
 
PatHartmanCommented:
You are building the RI somehow.  Stop building it.
0
 
davewalter1Author Commented:
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!
0
 
PatHartmanCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now