3 Replies - 16661 Views - Last Post: 26 September 2012 - 03:53 PM

#1 tarounen  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 17
  • Joined: 04-August 10

Creating a blank database using VBA

Posted 11 March 2012 - 08:31 AM

hi, i am trying to create a blank database using VBA, but so far i only know how to create a path directory. Here is what i have done:
Private Sub create_Click()
    If MsgBox("Backup file does not exist. Do you want to create it?", vbYesNo, "Update Confirmation") = vbYes Then
        MkDir "C:\backup.accdb"
    End If
End Sub 


can anyone, help me to create a file named backup.accdb and not a directory.

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a blank database using VBA

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Creating a blank database using VBA

Posted 11 March 2012 - 11:40 AM

To create a database from Access VBA
Application.DBEngine.CreateDatabase "C:\newfile.accdb", dbLangGeneral 
'or
Dim accessdb As Database
set accessdb = Application.DBEngine.CreateDatabase("C:\newfile.accdb", dbLangGeneral)



To create a database from Excel VBA
Dim accessApp As Access.Application    
Set accessApp = New Access.Application    
accessApp.DBEngine.CreateDatabase "C:\newfile.accdb", dbLangGenera

accessApp.Quit
set accessApp = nothing


Was This Post Helpful? 1
  • +
  • -

#3 tarounen  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 17
  • Joined: 04-August 10

Re: Creating a blank database using VBA

Posted 11 March 2012 - 11:09 PM

Thank you, it worked!!!!
Was This Post Helpful? 0
  • +
  • -

#4 iwanharnoko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-September 12

Re: Creating a blank database using VBA

Posted 26 September 2012 - 03:53 PM

View PostIonut, on 11 March 2012 - 11:40 AM, said:

To create a database from Excel VBA
Dim accessApp As Access.Application    
Set accessApp = New Access.Application    
accessApp.DBEngine.CreateDatabase "C:\newfile.accdb", dbLangGenera

accessApp.Quit
set accessApp = nothing

I have tried this code but error message still appear like this Run Time Error 3001:Application Defined or Object Defined Error, could anyone help me to solve this problem please?


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1