Create A Database with VB Code

  • Thread starter Thread starter Dangermouse
  • Start date Start date
D

Dangermouse

Hi, I'm new to VB, but what I'm after if possible is this.

via a macro call upon a module, which will create a temporary database, the
code I'm using is this code

Public Function CreateDatabase()

Dim db As Database

On Error GoTo ErrorHandler
Set db = DBEngine.CreateDatabase("c\ tmp\mydb.mdb", dbLangGeneral)

CreateDatabase = True
ErrorHandler:
If Not db Is Nothing Then db.Close

End Function

If I run the code manually, no errors appear, and no database created, if I
try and run the module via a macro, get an error message cant find function,
I am very confused

Cheers Dm
 
Dangermouse said:
Hi, I'm new to VB, but what I'm after if possible is this.

via a macro call upon a module, which will create a temporary database, the
code I'm using is this code

Public Function CreateDatabase()

Dim db As Database

On Error GoTo ErrorHandler
Set db = DBEngine.CreateDatabase("c\ tmp\mydb.mdb", dbLangGeneral)

CreateDatabase = True
ErrorHandler:
If Not db Is Nothing Then db.Close

End Function

If I run the code manually, no errors appear, and no database created, if I
try and run the module via a macro, get an error message cant find function,


Well, your function obliterated the builtin Access
function's name. Change your function's name to something
else such as MyCreateDB

You should also get rid if the space before tmp.
 
Back
Top