Help with ADO Execute command(Ex.db.Execute("Q_Matts_Qu

wren17

Board Regular
Joined
May 25, 2002
Messages
52
Hello everyone,

I am having a problem with executing Make-Table queries from VBA. The problem comes when I run the query and it tries to make a table that already exists. Normally if I were running the query manually. I would get the option to overwrite the existing table.

My question is: Does anyone know a way to execute a Make-Table query so that it will always overwrite the existing table instead of exitiing with an error.

Thanks,
Wren
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Re: Help with ADO Execute command(Ex.db.Execute("Q_Matt

Hi,

You'll need to delete the table first e.g.

On Error Resume Next
CN.Execute "DROP TABLE YourTableName"

'Your create table code


The on error statement is required in case the table doesn't already exist (the DROP TABLE statement will fail otherwise).
 
Upvote 0
You will create bloat in your database if you keep creating and deleting tables. It is better to just delete the existing records and append the new if you can.

Peter
 
Upvote 0
Re: Help with ADO Execute command(Ex.db.Execute("Q_Matt

Peter is right about the bloat -- but you can deal with that by regularly compacting the database (essential for the health of the DB anyway)

Denis
 
Upvote 0
bat17 said:
You will create bloat in your database if you keep creating and deleting tables. It is better to just delete the existing records and append the new if you can.

Peter

You'd also experience bloat using this method. As Denis has pointed out the only way to avoid this is to compact regularly.
 
Upvote 0
Deleting records also has the advantage of not disturbing any relationships or indexes created on the tables :)

Peter
 
Upvote 0

Forum statistics

Threads
1,221,558
Messages
6,160,484
Members
451,651
Latest member
Penapensil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top