Hello all,
I have an invoice template in Word97 which I am trying to fill. Each field on
the invoice is represented by a bookmark which i replace using the following
function:
function TfPrinterDialog.ReplaceBookmark(bkMark, NewText: string): boolean;
var
Param1, Param2, MyRange: olevariant;
begin
Result := true;
Param2 := wdGoToBookmark;
Param1 := bkMark;
if wrdDoc.Bookmarks.Exists(Param1) then begin
MyRange := wrdDoc.GoTo_(param2,EmptyParam,EmptyParam,param1);
MyRange.Select;
MyRange.Text := NewText;
end
else
Result := false;
end;
This mostly works, but I have a table with 4 columns and 5 rows that I am
having trouble with. The four columns are Service, Units, Cost, Price and
they have the row number as a suffix (Service1, Units1 etc..). I've built
another function to simplify this:
function TfPrinterDialog.PutToken(sToken: string; i: Integer; Temp:
string):boolean;
var
sTemp1: string;
begin
Result := false;
if i < 6 then begin
if Temp <> '' then begin
sTemp1 := sToken + inttostr(i);
result := ReplaceBookmark(sTemp1,Temp);
end;
end;
end;
which I call as follows:
for i := 1 to InvoiceDetailsQry.RecordCount do begin
PutToken('Service',i,IDQAction.Value);
PutToken('Units',i,IDQUnits.asstring);
PutToken('Cost',i,IDQPrice.asstring);
PutToken('Price',i,IDQItemCost.asstring);
InvoiceDetailsQry.Next;
end;
However after running this the first column, service, contains the value of
Price and none of the other bookmarks have been replaced! I've stepped
through and the variables seem to be passing correctly. I suspect Word may do
something funny with bookmarks in a table. If I stop it after service then
the service is correctly displayed in the table, so it is actually
overwriting the same field 4 times.
Is anyone familiar with this behavior?
thanks
Marc Pelletier
-----------------------------------------------------------------------------
Data Donkey - Geophysical Data Processing, Consulting and Software
Development
Creator of the POWER TOOLBOX utilities for OASIS montaj
contact: m...@datadonkey.com tel (306) 931-6853 or www.datadonkey.com