VBA in Excel to Create Table in Access

rsj88

New Member
Joined
Feb 20, 2018
Messages
38
Hi,

I am not able to find a good thread online regarding this.

I am trying to run a VBA script in Excel to run the following statement (Select * Into Table1 From (Select * From Data)

I have tried various scripts and many come across various errors.

The script should connect to the DB and Run the create table query. if the table already exists this should delete it first.

Any ideas please?

Thanks Team!!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Errors in code are part of the process. The task is to clear some and handle others.
Generally, You must create a connection (using ADODB or DAO) to the db and then use the connection's Execute method to run the SQL statement.
Post a sample code and we can try to get rid of the errors.
 
Upvote 0
yeah ive created the connection which is a ADODE connection.

This is referred to as

Module1.connect

Module 1.conn.execute ("Select * Into Table1 From (Select * From Data)
''Also tried Module 1.conn.execute ("Create_Table1")

Module1.disconnect

Error occurring is invalid SQL statement: expected delete insert procedure Select or update.
 
Upvote 0
try like this:
SQL:
Select * Into Table1 From Data
 
Upvote 0
Solution
Perfect Thanks. works now!

i had to put in a delete query to delete the table beforehand before we can create it as we are not able to overrate.
 
Upvote 0
You can use INSERT instead of SELECT INTO if the table exists.
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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