Solved

Create MS-Access database at run time

Posted on 1999-01-03
10
275 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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