Skip to content
Advertisement

How can a blank MS Access database be created using VBA?

I’m a total noob trying to create a blank MS Access database using VBA in Excel. I want to name the new database “tblImport”. This is the code I´m using:

   Sub makedb()
   Dim accessApp As Access.Application
   Set accessApp = New Access.Application
   accessApp.DBEngine.CreateDatabase "C:tblImport.accdb", dbLangGenera
   accessApp.Quit
   Set accessApp = Nothing
   End Sub

I get the following error message:

“Run Time Error 3001: Application Defined or Object Defined Error”

What can I do?

Advertisement

Answer

The name of the locale constant in the CreateDatabase method is wrong:

This:
accessApp.DBEngine.CreateDatabase "C:tblImport.accdb", dbLangGenera

Should be:
accessApp.DBEngine.CreateDatabase "D:tblImport.accdb", DB_LANG_GENERAL

Change that and your code should work. (It does for me at least).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement