Create a database in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know the syntax for creating a new database in code?

I want to run a macro which creates a database on the c drive, then exports
a table into that database. I want to recreate this everytime the macro is
executed.

Thanks for any help.

Sarah
 
This doesn't sound like a really good idea. What is it you are trying to
accomplish with this? Maybe there is a better way.
 
Klatuu said:
This doesn't sound like a really good idea. What is it you are
trying to accomplish with this? Maybe there is a better way.

What's wrong with the idea? Lots of applications provide an export
function; many non-Access applications provide an export-to-mdb
function. Why shouldn't an Access application provide a function to
export some subset of its data to a new .mdb file, for use by some
other, unknown application?
 
Sarah said:
Does anyone know the syntax for creating a new database in code?

I want to run a macro which creates a database on the c drive, then
exports a table into that database. I want to recreate this
everytime the macro is executed.

Assuming you've already got the path of the target file in a string
variable, you should be able to do something like this:

strTargetDB = "C:\Your Path\YourNewDB.mdb"

DBEngine.CreateDatabase strTargetDB, dbLangGeneral

DoCmd.TransferDatabase acExport, "Microsoft Access", _
strTargetDB, acTable, "YourTable", "YourTable"
 
I have a user of the database who needs this information (table) on a weekly
basis. Therefore I want him to be able to go into the database and press a
button which creates a new database on the c drive and exports the table that
is created by a make query into the new database.

What other way is there?
 
You do not need to create a new database each week fo this. The better way
to do this would be to create a database for the user to put on her C drive.
Create a macro that uses the TransferDatabase action to import the table from
the network database to their database. You can get detailed information on
TransferDatabase in Help. When the table is being imported and already
exists, it will allow you to overwrite the existing version with the new
version.
 
Does the current week's data replace the previous week's data or is each week
saved individually?
 
Why delete and create a new mdb on a weekly basis when a TransferDatabase
into an existing database would do just as well?
 
The problem I have with your suggestion is that several users will be doing
this and the users can change at anytime. Therefore I would always have to
make sure I knew who the users are and make sure they had that database on
their c drive. I don't want to have to do that kind of maintenance. I am
going to try Dirks suggestion.

Thank you.
 
Fine, but you still don't have to delete and recreate the database each time.
You can do the export to the user's database and it will still overwrite.

Will they do the export themselves manually or will you have to code
something that will know where the export has to go? Will you have to
rewrite the code when you add a new user?

Do it however you think is best, but I would think that providing a template
mdb with the import macro in it that they can copy from a shared folder once,
then do their own imports as needed would be less maintenace for you.

But what do I know, I'm a newbie, only been doing databases for 20 years.
 
Thank Dirk! That worked great!!!!!

Dirk Goldgar said:
Assuming you've already got the path of the target file in a string
variable, you should be able to do something like this:

strTargetDB = "C:\Your Path\YourNewDB.mdb"

DBEngine.CreateDatabase strTargetDB, dbLangGeneral

DoCmd.TransferDatabase acExport, "Microsoft Access", _
strTargetDB, acTable, "YourTable", "YourTable"


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
I'm not saying your suggestion wouldn't work. It's just that Dirk's
suggestion works without me having to set anything up for any user at any
time and the user doesn't need to copy a template to any location. They just
enter the database, press a button and the database is created for them on
the C drive. Don't you think that works better? No maintenance at all.
Don't you agree?

I've been working on databases for 18 years and I can always learn something
new. Maybe you can too.
 
Back
Top