Create a MS Access(.mdb) database file

Share this post
FaceBook  Twitter  Mixx.mn     

To create a new MS Access database, use following code:
Steps:
1) create a "ADOX" object

2) Delete file if already exist

3) Create a database using  "Provider=Microsoft.Jet.OLEDB.4.0;"

4) Discard all variables


Code:
'Create a MS Access(.mdb) database file
'=====================================================
Function Create_AccessDB(TempFilePath)
'1) create a "ADOX" object'
Set objADOXDatabase = CreateObject("ADOX.Catalog")
Set filesys = CreateObject("Scripting.FileSystemObject")

'2) Delete file if already exist '
If filesys.FileExists(TempFilePath) Then
   filesys.DeleteFile TempFilePath
End If

'3) Create a database using  "Provider=Microsoft.Jet.OLEDB.4.0;"'
objADOXDatabase.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                       "Data Source=" & TempFilePath
                       
'4) Discard all variables'                       
Set objADOXDatabase = Nothing
End Function