Solved

Create MS-Access database at run time

Posted on 1999-01-03
10
266 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 304
Delphi - replicating a form 8 74
How to renew a Delphi rad-studio licence? 5 65
Delphi Yen format 3 35
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

773 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