SQL with ADO

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
When using ADO to connect to/create an Access db, is it possible to execute SQL to create Tables, Primary Keys, etc...? or must this all be done using the ADOX.Catalog? :)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You can use ADO to create tables and the only way is using SQL.
 
Upvote 0
You can use ADO to create tables and the only way is using SQL.

Maybe I phrased the question wrong, instead of using...

Code:
    Set cat = New ADOX.Catalog
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDB_Path & ";"
    
    'create the table
    Set tbl = New ADOX.Table
    tbl.Name = "tblName"
    tbl.Columns.Append "ID", adInteger
    tbl.Columns.Append "Field1", adVarWChar, 60
    cat.Tables.Append tbl
    
    Set cat = Nothing
Using something like...

Code:
CREATE TABLE tblName (
ID Primary Key Not Null,
Field1, Text(60));
 
Upvote 0
I don't see why my post isn't clear.

You asked if you can use ADO to create tables etc using SQL, I said yes.
 
Upvote 0
Last edited:
Upvote 0
I don't see why my post isn't clear.

You asked if you can use ADO to create tables etc using SQL, I said yes.

I'm a little confused. You indicated that the ONLY way to create tables was via SQL. :confused:

The first example I provided was using the ADO Catalog and the second example is using SQL. I am able to utilize the first example, but not the second.
 
Upvote 0
Yes the only way to create tables etc in ADO is using SQL.

You're first example uses ADOX not ADO.
 
Upvote 0
Allen Browne gives some examples of SQL DDL using ADO here:
http://allenbrowne.com/func-DDL.html

If your attempt didn't work its probably some detail in the syntax or what have you - keep trying. Post your complete code if it still doesn't work.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,800
Members
449,337
Latest member
BBV123

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