Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening an MS Access Database within a Delphi application

Posted on 2006-12-01
7
Medium Priority
?
869 Views
Last Modified: 2010-04-05
I have a Delphi application which schedules the running of certain Access (2000) databases. Each database has an autoexec macro and performs a variety of functions.

This is running on my work computer though, and so atleast once an hour an MS Access database opens and stops me in the middle of work.

I would like it to open the MS Access databases within a Delphi form, or Delphi element of some sort.

Is this possible? If so, how?
0
Comment
Question by:wbstech
  • 3
  • 3
7 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18054679
What version of Delphi do you have and what do you want to do with Access.

If you just want to open the access tables and you have an enterprise version of Delphi you can use the ADO components to do this very easily.
Just drop an ADOCOnnection object onto your form and set the connectionstring (via the wizard in the object inspector).
Turn off LoginPrompt if you don't have to actually login to the database.
Now you can just turn the connection to the access database on and use the standard ADOQueries to run against the new connection to your access database.

If this is not what you are looking for them please provide a little more information.

0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 1000 total points
ID: 18054711
If you want to run access macros from delphi, here is some code from another PAQ.
First part was from me, second part from rllibby

I think its something like

procedure TForm1.Button1Click(Sender: TObject);
var
  Access: Variant;
begin
  Access := CreateOleObject('Access.Application');
  try
    Access.OpenCurrentDatabase('c:\db1.mdb');
    Access.DoCmd.RunMacro('Macro1');
  finally
    Access.Quit;
  end;
end;

Make sure the office server wrapper is installed in your delphi
componnets>install packages

Also not completely sure about the call to the macro, might be
AccessApplication1.DoCmd.RunMacro('Macro1',1,1);
 



Edit1 = name of your first edit box holding x:\path\msaccess.exe
Edit2 = name of your second edit box holding x:\path\database.mdb
MacroName = the name of your macro to run

  WinExec(PChar('"'+Edit1.Text+'" "'+Edit2.Text+'" /XMacroName'), SW_SHOWNORMAL);
0
 
LVL 4

Author Comment

by:wbstech
ID: 18054714
Ah should have mentioned, i'm on the ancient Delphi 4.

Each database being opened is running macros and queries of no specific type.
0
Technology Partners: 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!

 
LVL 4

Author Comment

by:wbstech
ID: 18054721
Would that above code function if I ran the autoexec macro, which in-turn runs multiple macros and queries? That would work for me.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18054888
You need to make sure that the office server wrapper is installed first.
You could test the calling of the macros then, but its been a long time since I was using anything near delphi 4 so I couldnt guarentee. All i can suggest is try it out.
0
 
LVL 9

Assisted Solution

by:bernani
bernani earned 1000 total points
ID: 18060201
Hi,

you can also try this if it helps:

{create a test.mdb database}
{add a test formular called Customers }
{add a second formular called Menu}
{Add a Macro called Autoexec wich call Macro1}
{Add a Macro1 wich opens the formular called "Customers" and which call Macro2}
{Add a Macro2 wich opens the formular Menu}
{Don't forget to change if needed the Security access for your macros: Tools->Security->... }

var
  Form1: TForm1;
  Access: Variant;     // Add this

implementation
 
{$R *.DFM}

Uses Comobj{for CreateOleObject};              // Add this

procedure TForm1.Button1Click(Sender: TObject);
begin
Access := CreateOleObject('Access.Application');
try
{Opens the database file with full qualified name, even in the same folder as your application}


  Access.OpenCurrentDatabase('C:\test.mdb');
  Access.DoCmd.RunMacro('Autoexec'); // execute Autoexec (wich invoke Macro1, display form Customers) which in turn execute macro2 (display form Menu).

//show Access application
  Access.visible:= true;                    // Add this
  finally
  {}
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Access.Quit;                                 //
Access:= unassigned;                   // Add this  
end;

0
 
LVL 4

Author Comment

by:wbstech
ID: 18301366
Thanks, both solutions helped me get to my final code.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

916 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