simple question of deleting a table

S

Southern at Heart

I have my code import a table from another database, but the trouble is, if
there's an old table by that same name [Name], then it imports the new one as
[Name1].
Can I have it overwrite the old one, or what is the code to just check if an
old one exists and delete it if it does.
thanks.
 
J

John W. Vinson

I have my code import a table from another database, but the trouble is, if
there's an old table by that same name [Name], then it imports the new one as
[Name1].
Can I have it overwrite the old one, or what is the code to just check if an
old one exists and delete it if it does.
thanks.

If the table is always of the same structure, you might want to not import at
all! Instead, run a delete query

DELETE * FROM [Name]:

to empty the table; Compact the database to recover the lost space; and *link*
to the remote table, and either just use that link directly, or (if you need a
copy of the data locally) run and Append query to populate the local table.
 
C

Christy Wyatt

--
Christy Wyatt


Southern at Heart said:
I have my code import a table from another database, but the trouble is, if
there's an old table by that same name [Name], then it imports the new one as
[Name1].
Can I have it overwrite the old one, or what is the code to just check if an
old one exists and delete it if it does.
thanks.

I would use a Make Table query, since that would automatically overwrite the
existing table. You can use code to run the Make Table Query automatically
when an even occurs.
 
S

Southern at Heart

How do I use the maketable method with importing my table? I have this:

DoCmd.TransferDatabase acImport, "Microsoft Access", strFolderFile, acTable,
"Name", "Name"

....which creates the table, but numbers it if another one already exists. I
just need it to write over the old one.
thanks.

Christy Wyatt said:
--
Christy Wyatt


Southern at Heart said:
I have my code import a table from another database, but the trouble is, if
there's an old table by that same name [Name], then it imports the new one as
[Name1].
Can I have it overwrite the old one, or what is the code to just check if an
old one exists and delete it if it does.
thanks.

I would use a Make Table query, since that would automatically overwrite the
existing table. You can use code to run the Make Table Query automatically
when an even occurs.
 
J

John W. Vinson

How do I use the maketable method with importing my table? I have this:

DoCmd.TransferDatabase acImport, "Microsoft Access", strFolderFile, acTable,
"Name", "Name"

...which creates the table, but numbers it if another one already exists. I
just need it to write over the old one.
thanks.

Well... then don't DO it that way.

Don't do a Maketable.
Don't do an Import.

Instead, *LINK* to the extrnal table, and run an Append query appending to the
local table. You may want to run a Delete query to empty the table first.
 

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