?
Solved

Access VBA Create SQL Database

Posted on 2012-08-23
2
Medium Priority
?
508 Views
Last Modified: 2012-08-27
Hi

I use the following Access VBA code to create new SQL tables. How do I create a new SQL database using similar code

Sub oCreate_Online_Table
Dim  sSQL As String

sSQL = "CREATE TABLE Categories "
sSQL = sSQL & "([ID] char not null primary key, [Main Category] nvarchar(30) not null, [Sub Category] nvarchar(30) not null)"
   
    On Error GoTo EH
   
    Set con = New ADODB.Connection
    con.Open "Provider=SQLOLEDB;Data Source=41...100;Network Library=DBMSSOCN;Initial Catalog=MagicBox_Doppio;User ID=x...g;Password=bvcv;"
             
    Set cmd = New ADODB.Command    
    With cmd
        .CommandText = sSQL
        .CommandType = adCmdText
        .ActiveConnection = con
        .Execute
    End With
   
   
    Set cmd = Nothing
    Set con = Nothing
    Exit Sub
EH:  
    MsgBox Err.Description
End Sub
0
Comment
Question by:Murray Brown
2 Comments
 
LVL 16

Accepted Solution

by:
kmslogic earned 2000 total points
ID: 38327455
CREATE DATABASE MyDatabaseName;

should work as long as you have privs to do that.
0
 

Author Closing Comment

by:Murray Brown
ID: 38337873
Thanks very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question