Board index » delphi » Mail merge and Word 2K... stuck again

Mail merge and Word 2K... stuck again

I am using templates created in Word2K with standard merge fields, as
example:

?Adres?
You, ?Patient?, are presently ....

The two <<name>> fields are my merge fields. The idea is that my user
utilise these supplied standard merge names in any template that they write,
and I simply replace and print from out of my database app with the
following code:

Procedure tfrmMerge.ReplaceBookmark(cBookMark,cData: String);
Begin
   // Find & replace...
   If nbWordVersion=8 then
oleWordApplication.WordBasic.EditBookMark(cBookMark,0,0,0,1)
    else oleWordApplication.EditGoto(cBookMark);
   oleWordApplication.Selection.TypeText(cData);
End;

I use a call:   ReplaceBookmark('Adres','Tree number 12');

All works OK, Word starts, opens the template BUT THEN does not recognise
the bookmark name. Am I using the wrong method for Word?

Can someone please help me out? Thanks in advance    : (

her...@thebitfactory.co.za
Herman Wapenaar

 

Re:Mail merge and Word 2K... stuck again


Hi,

If you want to use a mail merge, I suggest you don't use bookmarks.
If you create a datafile, you can easily merge it to a document. It works
fine and is a better solution if you want to send a document to several (in
your case) patients.

Regards,

Filip.

Quote
> ?Adres?
> You, ?Patient?, are presently ....

> The two <<name>> fields are my merge fields. The idea is that my user

Re:Mail merge and Word 2K... stuck again


Using Word 97 the following code works fine for me

    i := 1;
    i1 := 0;
    First := True;
    while (i <= anz) and (i1 < 20) do
    begin
      ToWhat  := wdGotoField;
      if First then
      begin
        ToWhich := wdGoToFirst;
        WordApplication1.Selection.GoTo_ (ToWhat, ToWhich, EmptyParam, EmptyParam);
      end
      else
      begin
        ToWhich := wdGoToNext;
        WordApplication1.Selection.GoTo_ (ToWhat, ToWhich, EmptyParam, EmptyParam);
      end;
      First := False;
      t := WordApplication1.Selection.End_;
      WordApplication1.Selection.End_ := WordApplication1.Selection.End_ + 30;
      StrToAdd := WordApplication1.Selection.Text;
      if (length (StrToAdd) > 0) and (StrToAdd [1] = '?') then
      begin
        Delete (StrToAdd,1,1);
        Delete (StrToAdd, length (StrToAdd),1);
        StrToAdd := GetNewText (StrToAdd);  (* get the new text to insert in word *)
        WordApplication1.Selection.End_ := t;
        WordApplication1.Selection.Delete (EmptyParam, EmptyParam);
        WordApplication1.Selection.TypeText(StrToAdd);
        inc (i);
      end
      else
      begin
        inc (i1);
        WordApplication1.Selection.End_ := t;
      end;

--
Bj?rn Gundermann
"Herman Wapenaar" <hwa...@iafrica.com> schrieb im Newsbeitrag news:8br67g$h7f7@bornews.borland.com...

Quote
> I am using templates created in Word2K with standard merge fields, as
> example:

> ?Adres?
> You, ?Patient?, are presently ....

> The two <<name>> fields are my merge fields. The idea is that my user
> utilise these supplied standard merge names in any template that they write,
> and I simply replace and print from out of my database app with the
> following code:

> Procedure tfrmMerge.ReplaceBookmark(cBookMark,cData: String);
> Begin
>    // Find & replace...
>    If nbWordVersion=8 then
> oleWordApplication.WordBasic.EditBookMark(cBookMark,0,0,0,1)
>     else oleWordApplication.EditGoto(cBookMark);
>    oleWordApplication.Selection.TypeText(cData);
> End;

> I use a call:   ReplaceBookmark('Adres','Tree number 12');

> All works OK, Word starts, opens the template BUT THEN does not recognise
> the bookmark name. Am I using the wrong method for Word?

> Can someone please help me out? Thanks in advance    : (

> her...@thebitfactory.co.za
> Herman Wapenaar

Other Threads