rwasaff
asked on
Delphi 5 Word Servers and Merging Information
My company uses Word documents as forms. Now they just print out the forms and then fill in the blanks. What I want to do is use the new D5 Servers and by using some type of mail merge field on the word 97 document, fill in and print the document in the background not showing the word document or Word at all. I am getting my information from an Access 97 database and need to insert information of all tipes into the Word Document--Text, numbers, memo and boolean. I am new at using D5's Servers so it would be nice for an example or a website for me to get information from. I also have about 500 docs to change if I can get this working, so I would appreciate a simple change for the doc files.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is how I did it.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
{$IFDEF VER130}
Word97,
{$ELSE}
Word_TLB,
{$ENDIF}
StdCtrls, Db, DBTables, Dialogs, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
opdlOpen: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
Word: _Application;
Doc: _Document;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses ComObj, ActiveX;
procedure TForm1.BitBtn1Click(Sender : TObject);
var
Pause, sFilename: OleVariant;
i : Integer;
begin
if opdlOpen.execute = True then
begin
sfilename := opdlOPen.filename;
Doc := Word.Documents.open(sFileN ame,EmptyP aram,Empty Param,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am);
Pause := False;
with Doc.MailMerge do
begin
Destination := wdSendToNewDocument;
Datasource.FirstRecord := wdDefaultFirstRecord;
Datasource.LastRecord := integer(wdDefaultLastRecor d);
Execute(Pause);
end;
doc.PrintOut(EmptyParam,Em ptyParam,E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am,EmptyPa ram,EmptyP aram,Empty Param,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam )
end;
showmessage('Done');
for i := 0 to 10 do
Beep;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
SaveChanges: OleVariant;
begin
SaveChanges := wdDoNotSaveChanges;
Word.Quit(SaveChanges, EmptyParam, EmptyParam);
Doc := nil;
Word := nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Unknown: IUnknown;
Result: HResult;
begin
{$IFDEF VER120} // Delphi 4
Result := GetActiveObject(CLASS_Appl ication_, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Word := CoApplication_.Create
{$ELSE} // Delphi 5
Result := GetActiveObject(CLASS_Word Applicatio n, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Word := CoWordApplication.Create
{$ENDIF}
else begin
{ make sure no other error occurred during GetActiveObject }
OleCheck(Result);
OleCheck(Unknown.QueryInte rface(_App lication, Word));
end;
Word.Visible := False;
end;
end.
I got this info from
http://www.djpate.freeserve.co.uk/AutoWord.htm
Hope this helps
Ross
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
{$IFDEF VER130}
Word97,
{$ELSE}
Word_TLB,
{$ENDIF}
StdCtrls, Db, DBTables, Dialogs, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
opdlOpen: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
Word: _Application;
Doc: _Document;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses ComObj, ActiveX;
procedure TForm1.BitBtn1Click(Sender
var
Pause, sFilename: OleVariant;
i : Integer;
begin
if opdlOpen.execute = True then
begin
sfilename := opdlOPen.filename;
Doc := Word.Documents.open(sFileN
Pause := False;
with Doc.MailMerge do
begin
Destination := wdSendToNewDocument;
Datasource.FirstRecord := wdDefaultFirstRecord;
Datasource.LastRecord := integer(wdDefaultLastRecor
Execute(Pause);
end;
doc.PrintOut(EmptyParam,Em
end;
showmessage('Done');
for i := 0 to 10 do
Beep;
end;
procedure TForm1.FormDestroy(Sender:
var
SaveChanges: OleVariant;
begin
SaveChanges := wdDoNotSaveChanges;
Word.Quit(SaveChanges, EmptyParam, EmptyParam);
Doc := nil;
Word := nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Unknown: IUnknown;
Result: HResult;
begin
{$IFDEF VER120} // Delphi 4
Result := GetActiveObject(CLASS_Appl
if (Result = MK_E_UNAVAILABLE) then
Word := CoApplication_.Create
{$ELSE} // Delphi 5
Result := GetActiveObject(CLASS_Word
if (Result = MK_E_UNAVAILABLE) then
Word := CoWordApplication.Create
{$ENDIF}
else begin
{ make sure no other error occurred during GetActiveObject }
OleCheck(Result);
OleCheck(Unknown.QueryInte
end;
Word.Visible := False;
end;
end.
I got this info from
http://www.djpate.freeserve.co.uk/AutoWord.htm
Hope this helps
Ross
opdlOpen is an OpenDialog box.
Ross
Ross
The Beep stuff was just for fun.
Ross
Ross
ASKER
Sorry it took me so long to get back. You know how other things become more important at times.
I finally got to look at the examples and web sites you all suggested. An I would like to give each of you 100 points if I could. Could you tell me how to do this? Do I just Accept each answer and would you get each 100 points. This is what I want to do.
You all were a big help. Thanks
Bob
I finally got to look at the examples and web sites you all suggested. An I would like to give each of you 100 points if I could. Could you tell me how to do this? Do I just Accept each answer and would you get each 100 points. This is what I want to do.
You all were a big help. Thanks
Bob
hi,
nice idea ;-)
to do so you have to ask new questions to each expert (just put experts name in title) then experts will put something (eg hello )as answer for question and then can get points..
yopu can accept one of the comments here as answer also or delete this question then ..
Regards Barry
nice idea ;-)
to do so you have to ask new questions to each expert (just put experts name in title) then experts will put something (eg hello )as answer for question and then can get points..
yopu can accept one of the comments here as answer also or delete this question then ..
Regards Barry
ASKER
Comment accepted as answer
ASKER
And Thank you Again for the informstion
Here's another place that may help, especialy the word components.
http://www.capturebeat.com
I've only created one program similar to what you've described, I found it useful to create word fields for all of the input areas, that made it much easier to navigate the doc.
Cheers - Walter McKie