[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Create MS-Access database at run time

Posted on 1999-01-03
Medium Priority
Last Modified: 2010-04-04
is it possible (preferably using the ODBC Access driver, but if this isnt possible, then using the native driver)
to create an MS-Access Database at run time?  I want to take a set of records from a table in one database, create a new database (ie .MDB file) and export my set of records into this new database (table structure is the same)

I can create a temporary table inside the original database with the set of records I want to export, but Im not sure how to create a new database, and copy the temp table into it.

can anyone help?
Question by:1750
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3

Expert Comment

ID: 1354374
Nope! ..It's not possible to create a Database just like this. I can only help you with creating a dummy database by writing raw filedata to a dummy file, and then create the tables inside it using ODBC connect.

I'm sorry, I don't think there's a pretty way to do this.


Expert Comment

ID: 1354375
Williams2 is right.  Also if you want to go the component route there is a component called Diamond Access which will allow direct DAO calls to the jet engine.  This will do what you want but it costs $99.00.  However, I use Access Databases with Delphi frequently and I cant think of a better way you could spend 99 bucks.  This is an indespendsible component.  You can find it on any of the better Delpi site (DSP, Torry's, DelphiX).  Hope this helps
LVL 27

Expert Comment

ID: 1354376
hi friends,

i think there is a way with jet-sql from access, but here at home i cannot check out it (no access here). Will you wait until Thursday, i will comment a way or comment thats this is not possible.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1354377
Sure we can wait till thursday.

LVL 27

Expert Comment

ID: 1354378
hi 1750,

sorry, i couldn't configure out a way to create a Access Database, so that i say there is no way to create a database at runtime.

a other way is to work with an empty Access-Database template and code like this

procedure TForm1.Button1Click(Sender: TObject);
var ok : Bool;
  copyfile('C:\Delphi 3\empty.mdb','C:\Delphi 3\test.mdb',Ok); {copy template to a working database}
  if ok then
    query1.execsql; {is connected to Northwind.mdb and holds SQL-String :
select * into Artikel2 in Test.mdb from artikel (here can be a where-clause)
-> copy whole Artikel-Table into test.mdb with name Artikel2}


Expert Comment

ID: 1354379
I think I could make it a bit more useful like including the empty template as a binary resource in my project source. I think it would look more pretty this way :-)

LVL 12

Expert Comment

ID: 1354380
I've found it! Theres a component on DSP (http://sunsite.icm.edu.pl/delphi) which is free, has the source and creates access mdb's via DAO:

Check it out: copyso22.zip (http://sunsite.icm.edu.pl/delphi/ftp/d20free/copyso22.zip)

Free beats $99 any day in my book :-)



Author Comment

ID: 1354381
Ive just had a look at the copyso22 project, and I dont think its much help.  Its not a component, just a demo app showing how to do a few things, mostly with paradox and dbase.  I cant find anywhere in the app, or the source, anywhere where it can create a new database file (.mdb)

The way I have done it is similar to kretzschmar's solution, with an empty template.

I have found another component though, by a guy called Pierre du Parté, called the 'TmsaUtility' Component, and described as "A simple component that uses OLEAutomation to Repair and Compress Microsoft Access (MDB) Data Files"

it can also create MDB files.  it seems to work quite well.  he is working on a new release that does a bunch of other stuff as well.  Its also completely free.

the URL is http://www.finalfiler.com/

Accepted Solution

apaparis earned 300 total points
ID: 1354382
You can create a new mdb file:
   Var V : Variant
   V := CreateOleObject('DAO.DBEngine');
   //               full path
   V.CreateDatabase('C:\Test\Temp.MDB', ';LANGID=0x0409;CP=1252;COUNTRY=0');

create your table using TQuery and "create table ..."
and copy data
1st method: using two TTable component, one for the source table and the other for the destination.
2nd method : use TBatchMove (is faster)


Author Comment

ID: 1354383
yeah - thats the way the TmasUtility component works...

seems to work fine.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question