Solved

Opening an MS Access Database within a Delphi application

Posted on 2006-12-01
7
701 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 202
shape, triangle, dbctrlgrid 3 46
Browsing a TTreeView in Delphi 5 48
Connect to SQL 2008 r2 server over the Internet 4 80
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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