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?
Step 1 : Start by opening MS – Access. Step 2 : Select Blank Database. Step 3 : In the file name field enter a name for the database. Step 4 : Clickl Create.
Way 1: Create Access database with templates. Way 2: Create a blank Access database with “Blank database” or “Blank Web database” command. Way 3: Import existing data into Microsoft Access and save as Access database.
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).
Old Question. Here are my two cents. You have a typo...
dbLangGenera
should be dbLangGeneral
More about it in Workspace.CreateDatabase Method (DAO)
Voting to close this question as per Dealing with questions with obvious replies
Try this. This works.
Sub makedb()
Dim accessApp As Access.Application
Set accessApp = New Access.Application
accessApp.DBEngine.CreateDatabase "C:\tblImport.accdb", dbLangGeneral
accessApp.Quit
Set accessApp = Nothing
End Sub
EDIT: Will delete this answer and post it as a comment once the post is closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With