Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Francisc Molnar
 
Posts: n/a
Default retrieving merge field names

Hi all
I am programmatically(C#, using the PIA) changing the datasource for a word
document, wich contains some merge fields.
In order to avoid the prompt wich signals that certain fields have no
correspondent in the new datasource, I would like to obtain the merge field
names and check if the datasource has a corresponding column for each one of
them (if not - I will not call MailMerge.Execute()).
I cannot find a reasonable way to retrieve the merge field name (I cannot
obtain it like this: field - field ... it's not always the same.)
Should I parse the MailMergeField.Code.Text ? ... I think it's not a very
good idea...
Thanks

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default retrieving merge field names

The following VBA code will give you the names of the mergefields in the
activedocument:

Dim af As Field
For Each af In ActiveDocument.Fields
If af.Type = wdFieldMergeField Then
MsgBox Mid(af.Code, InStr(af.Code, Chr(34)))
End If
Next af

You may need to strip off the quote marks for your purposes.

Can't help you with C#

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Francisc Molnar" wrote in
message ...
Hi all
I am programmatically(C#, using the PIA) changing the datasource for a
word
document, wich contains some merge fields.
In order to avoid the prompt wich signals that certain fields have no
correspondent in the new datasource, I would like to obtain the merge
field
names and check if the datasource has a corresponding column for each one
of
them (if not - I will not call MailMerge.Execute()).
I cannot find a reasonable way to retrieve the merge field name (I cannot
obtain it like this: field - field ... it's not always the same.)
Should I parse the MailMergeField.Code.Text ? ... I think it's not a very
good idea...
Thanks



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Mail Merge include a space at the beginning of a field? Joshua Mailmerge 5 April 13th 06 06:37 AM
Database Query on Merge field KarenB Mailmerge 7 April 3rd 06 05:34 PM
Suppressing Merge Field and text before/after julie Microsoft Word Help 8 November 14th 05 02:50 PM
Word merge field names vs. Excel merge field names [email protected] Mailmerge 5 November 11th 05 05:24 PM
mail merge field names Edwin Patrick Mailmerge 4 March 9th 05 10:57 PM


All times are GMT +1. The time now is 10:53 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"