Access VBA Create SQL Database

Posted on 2012-08-23
Last Modified: 2012-08-27

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
    End With
    Set cmd = Nothing
    Set con = Nothing
    Exit Sub
    MsgBox Err.Description
End Sub
Question by:murbro
    LVL 16

    Accepted Solution

    CREATE DATABASE MyDatabaseName;

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

    Author Closing Comment

    Thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now