PC Review


Reply
Thread Tools Rate Thread

Create A Database with VB Code

 
 
Dangermouse
Guest
Posts: n/a
 
      10th Mar 2009
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

 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      10th Mar 2009
Dangermouse wrote:

>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.

--
Marsh
MVP [MS Access]
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a database using VB Code Dangermouse Microsoft Access VBA Modules 1 10th Mar 2009 03:53 PM
create new blank database by VBA code =?Utf-8?B?Vi5QLg==?= Microsoft Access VBA Modules 5 31st Aug 2006 11:01 PM
Create a database in code =?Utf-8?B?U2FyYWg=?= Microsoft Access Form Coding 12 7th Jun 2006 10:25 PM
how do I create a database using post code =?Utf-8?B?S2V2YW53?= Microsoft Access Queries 1 30th Mar 2006 01:21 AM
Can't create new database using VBA code Robert Microsoft Access Database Table Design 5 10th Dec 2003 01:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 AM.