0
votes

could anyone help?

I've inherited some software written in Delphi 5 which allows member data and fields from a database (.ADT file) to be used merged in to word.

It works fine with all version of Word except 2010 where it won't load any documents and shows the error:

"That Method is not available on that object"

I have been told the solution is to replace the preset components OpWord and OpDataSet with Ole variants. I have done so with OpWord using:

wrdApp := CreateOleObject('Word.Application');

and the documents now load up but without any merge field data. Can anyone let me know how to extract this data from the database, as the OpDataSet seems to simply just point at the table?

Or can anyone suggest a better solution than the one I'm trying. I'm very new to Delphi so I'm in abit over my head

Edit: (Requested Info)

Sorry I have more details and code if required.

The components appear to belong to a library called OfficePartner along with TOpExcel,TOpOutlook and others.

The .doc is selected from a popup ListPane on Form30, opened and populated with merge field data from Table 4. Table 1 is the members database:

  {Use Table4 as we can Set a range on it}
  Table4.SetRange([Table1.FieldByName('Member Id').AsString],[Table1.FieldByName('Member Id').AsString]);

  {Open Word}
  OpWord1.Connected := True;

  {Open the Test Document}
  OpWord1.OpenDocument(DocumentDirectory + '\' + Form30.ListBox1.Items[Form30.ListBox1.ItemIndex]);

  {Populate the Test Document}
  OpWord1.ActiveDocument.MailMerge.OfficeModel := OpDataSetModel1;
  OpWord1.ActiveDocument.PopulateMailMerge;
  OpWord1.ActiveDocument.ExecuteMailMerge;

I hope this helps...

1
Without some code and a better indication of where/which library OpWord and OpDataSet are coming from (they certainly are not standard Delphi 5 components), it's anybody's guess. Show how you create the various COM objects (not just the word app) and how you open the document and/or start the merge.Marjan Venema
Hi thanks for replying. Apologies I didn't want to write such a long question but I've included some code in the edit above.notidaho

1 Answers

1
votes

Here is a little procedure for word mail merge that I used way back for D6, it's a just snippet and you have to include in some class, I don't have Delphi anymore so can't compile to make sure that it works, anyway here it is, hope it helps:

procedure MailMergeWord;
var
  WordApp: TWordApplication;
  WordDoc: TWordDocument;
  doc : WordDocument;
  FileName: OleVariant;
  xx: integer;
begin
  WordApp := TWordApplication.Create(nil);
  WordApp.ConnectKind := ckNewInstance;
  WordDoc := TWordDocument.Create(WordApp);
  FileName := 'TemplateDoc.doc';

  doc := WordApp.Documents.Open(FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                                 ,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                                 ,EmptyParam);

  WordDoc.ConnectTo(Doc);
  for xx := 1 to WordDoc.Fields.Count do
    WordDoc.Fields.Item(xx).Result.Text := OnWordVariable(WordDoc.Fields.Item(xx).Code.Text);
  WordDoc.PrintOut;
  WordDoc.Free;
  WordApp.Free;
end;


function OnWordVariable(varName: string): string;
begin
  Result := 'Value based on variable name';
end;