Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create an Access database at runtime Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Create an Access database at runtime 15-Aug-02
Category
ADO/OLE-DB
Language
Delphi 4.x
Views
138
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to create an Access database at runtime

Answer:

Solve 1:

Here is an OP function that will do it for you:
1   
2   procedure CreateMSAccessDB(filename: string);
3   var
4     DBEngine, Workspace: Variant;
5   const
6     {Important to use the following constant as is}
7     dbLangGeneral = '';
8     LANGID = 0x0409;
9     CP = 1252;
10    COUNTRY = '0';
11    dbVersion30 = 32;
12  begin
13    DBEngine := CreateOleObject('DAO.DBEngine');
14    {DBEngine := CreateOleObject('DAO.DBEngine.35'); For DAO 3.5}
15    Workspace := DBEngine.Workspaces[0];
16    try
17      Workspace.CreateDatabase(filename, dbLangGeneral, dbVersion30);
18    except
19      on EOleException do
20        ShowMessage('Database already exists');
21    end;
22  end;



Solve 2:

It's very simple to create a empty Access-Database (*.mdb File) using OLE. It's not 
necessary to have MS-Access installed on your computer. If an exception occures the 
error message will returned. After creating the DB you can create Tables with 
simple SQL-Statements. 
23  
24  uses comobj, sysutils;
25  
26  function CreateAccessDatabase(FileName: string): string;
27  var
28    cat: OLEVariant;
29  begin
30    result := '';
31    try
32      cat := CreateOleObject('ADOX.Catalog');
33      cat.create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + Filename + ';');
34      cat := NULL;
35    except
36      on e: Exception do
37        result := e.message;
38    end;
39  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC