I've written this program which at the mo only has two buttons. One to exit the program and the other to open a report from an external Microsoft Access database file. I'm getting this error message:

Debugger Exception Notification - Project Project1.exe raised exception class EOleSysError with message "Operation Unavailable". Process Stopped. Use Step or Run to continue.

Here's the code:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,  ComObj;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var
Access: Variant;
 const
    acViewNormal = $00000000;
    acViewDesign = $00000001;
    acViewPreview = $00000002;
begin
  try
    Access := GetActiveOleObject('Microsoft Access.Application');
  except
    Access := CreateOleObject('Access.Application');
  end;
  Access.Visible := True;
  Access.OpenCurrentDatabase('P:\ICT\Write\Computing\CPT L6\NEW CPT3\XmnrTable.mdb', True);
  Access.DoCmd.OpenReport ('Report 1', acViewPreview, EmptyParam, EmptyParam);
  Access.CloseCurrentDatabase;
  Access.Quit(1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.terminate;
end;
end.

Any help would be much appreciated :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.