Solved

Opening an MS Access Database within a Delphi application

Posted on 2006-12-01
7
764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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
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!

 
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 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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