Solved

Create MS-Access database at run time

Posted on 1999-01-03
10
286 Views
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?
0
Comment
Question by:1750
[X]
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
10 Comments
 
LVL 3

Expert Comment

by:williams2
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.

Regards,
Williams
0
 
LVL 5

Expert Comment

by:heathprovost
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
0
 
LVL 27

Expert Comment

by:kretzschmar
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.

meikl
0
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

by:1750
ID: 1354377
Sure we can wait till thursday.

thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
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;
begin
  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}
end;

meikl
0
 
LVL 3

Expert Comment

by:williams2
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 :-)

Regards,
Williams
0
 
LVL 12

Expert Comment

by:rwilson032697
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 :-)

Cheers,

Raymond.
0
 

Author Comment

by:1750
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/
0
 
LVL 1

Accepted Solution

by:
apaparis earned 100 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)

0
 

Author Comment

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

seems to work fine.

Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Delphi: ForceDirectory plain function 7 81
Breakpoint doesn't stop in my variable 3 46
DBCtrlGrid, Delphi, Scroll 7 34
Get weeknumber and year from date 4 55
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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