Create a blank Access Database from Excel

Vishesh's picture
Following is a small piece of code to create a blank Access Database. Paste it in a general module and call it using the required parameters - the database path and name.
Sub TestRun()
 
    Call CreateAccessDatabase("C:\Users\Vishesh\Documents\MyDocuments\Excel VBA\Test", "ABC")
 
End Sub
 
 
 
Private Sub CreateAccessDatabase(strDBPath As String, strDBName As String)
 
    Dim objCatalog              As Object
 
    Dim objConnection           As Object
 
    Dim strConnectionString     As String
 
    Dim strFullDBPath           As String
 
 
 
    Set objConnection = CreateObject("ADODB.Connection")
 
    'Set database name here

    strFullDBPath = strDBPath & Application.PathSeparator & strDBName & ".mdb"
 
    strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFullDBPath & ";"
 
 
 
    'Create new database

    Set objCatalog = CreateObject("ADOX.Catalog")
 
    objCatalog.Create strConnectionString
 
 
 
    Set objCatalog = Nothing
 
    Set objConnection = Nothing
 
End Sub

Thanks!

Worked perfectly, first time.