Solved

Create MS-Access database at run time

Posted on 1999-01-03
10
245 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:1750
Comment Utility
Sure we can wait till thursday.

thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:williams2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
yeah - thats the way the TmasUtility component works...

seems to work fine.

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now