Create A Database with VB Code

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
 
M

Marshall Barton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top