Group:  Microsoft Word ยป microsoft.public.word.mailmerge.fields
Thread: how to map mailmerge fields?

Geek News

how to map mailmerge fields?
"b.schmidt" <shocker843[ at ]hotmail.com> 5/9/2007 10:49:27 AM
hi,

I added a csv-file as DataSource to a Word Document (I'm using VSTO, C#
and Word 2007), which worked fine. Now I was wondering, how I can map
the columns I declared in the first line of the csv-file to the fields
Word uses for mailmerge?

I tried to use MappedDataFields, but whenever I tried to write to a
MappedDataField.DataFieldName it tells me that this property is read-only?

I'm a bit confused...

best regards,
Bernhard
Re: how to map mailmerge fields?
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/9/2007 11:59:59 AM
[Quoted Text]
> the columns I declared in the first line of the csv-file to the fields
> Word uses for mailmerge?

You only need to map fields if you are using merge fields that rely on
mapping, such as ADDRESSBLOCK and GREETINGLINE, or if you want to use
mapping and use the standardlist of "Address Field" names with the "\m"
switch in the MERGEFIELD fields.

Not sure about Word 2007 but in Word 2003 you can't assign to the name. You
can work around this by assigning one index to another, e.g. to assign the
Address field "City" to the first column in the data source in VBA, you
might use:

Dim objMDFs As MappedDataFields
Set objMDFs = ActiveDocument.MailMerge.DataSource.MappedDataFields
objMDFs(wdCity).DataFieldIndex = 1
Set objMDFs = Nothing

i.e. if you want to assign the data source fied called "Town" to the mapped
field "City", you will probably need to iterate through the
ActiveDocument.MailMerge.DataSource.DataFields collection looking for the
field whos ename is "Town", and use its index value to set the
MappedDataFields.DataFieldIndex.

Peter Jamieson

"b.schmidt" <shocker843[ at ]hotmail.com> wrote in message
news:%23qHD%23eikHHA.1992[ at ]TK2MSFTNGP05.phx.gbl...
> hi,
>
> I added a csv-file as DataSource to a Word Document (I'm using VSTO, C#
> and Word 2007), which worked fine. Now I was wondering, how I can map the
> columns I declared in the first line of the csv-file to the fields Word
> uses for mailmerge?
>
> I tried to use MappedDataFields, but whenever I tried to write to a
> MappedDataField.DataFieldName it tells me that this property is read-only?
>
> I'm a bit confused...
>
> best regards,
> Bernhard


Re: how to map mailmerge fields?
"b.schmidt" <shocker843[ at ]hotmail.com> 5/10/2007 12:09:14 PM
Thanks, using the DataFieldIndex worked. :)

Strange though that the MappedDataField.DataFieldName is stated as
"Read/write" on MSDN, although Visual Studio says it's read-only...

http://msdn2.microsoft.com/en-us/library/bb224166.aspx

Thank you very much for your help. :)


Peter Jamieson, am 09.05.2007 13:59:
[Quoted Text]
>> the columns I declared in the first line of the csv-file to the fields
>> Word uses for mailmerge?
>
> You only need to map fields if you are using merge fields that rely on
> mapping, such as ADDRESSBLOCK and GREETINGLINE, or if you want to use
> mapping and use the standardlist of "Address Field" names with the "\m"
> switch in the MERGEFIELD fields.
>
> Not sure about Word 2007 but in Word 2003 you can't assign to the name. You
> can work around this by assigning one index to another, e.g. to assign the
> Address field "City" to the first column in the data source in VBA, you
> might use:
>
> Dim objMDFs As MappedDataFields
> Set objMDFs = ActiveDocument.MailMerge.DataSource.MappedDataFields
> objMDFs(wdCity).DataFieldIndex = 1
> Set objMDFs = Nothing
>
> i.e. if you want to assign the data source fied called "Town" to the mapped
> field "City", you will probably need to iterate through the
> ActiveDocument.MailMerge.DataSource.DataFields collection looking for the
> field whos ename is "Town", and use its index value to set the
> MappedDataFields.DataFieldIndex.
>
> Peter Jamieson
>
> "b.schmidt" <shocker843[ at ]hotmail.com> wrote in message
> news:%23qHD%23eikHHA.1992[ at ]TK2MSFTNGP05.phx.gbl...
>> hi,
>>
>> I added a csv-file as DataSource to a Word Document (I'm using VSTO, C#
>> and Word 2007), which worked fine. Now I was wondering, how I can map the
>> columns I declared in the first line of the csv-file to the fields Word
>> uses for mailmerge?
>>
>> I tried to use MappedDataFields, but whenever I tried to write to a
>> MappedDataField.DataFieldName it tells me that this property is read-only?
>>
>> I'm a bit confused...
>>
>> best regards,
>> Bernhard
>
>
Re: how to map mailmerge fields?
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/10/2007 1:12:08 PM
[Quoted Text]
> Strange though that the MappedDataField.DataFieldName is stated as
> "Read/write" on MSDN, although Visual Studio says it's read-only...

Let me put it this way: I always try to avoid basing any statement on the
evidence of the official documentation alone, whatever its origin. When I
have, I've almost invariably regretted it. And that hasn't changed for over
25 years...

Peter Jamieson


"b.schmidt" <shocker843[ at ]hotmail.com> wrote in message
news:eZTIPwvkHHA.4152[ at ]TK2MSFTNGP04.phx.gbl...
> Thanks, using the DataFieldIndex worked. :)
>
> Strange though that the MappedDataField.DataFieldName is stated as
> "Read/write" on MSDN, although Visual Studio says it's read-only...
>
> http://msdn2.microsoft.com/en-us/library/bb224166.aspx
>
> Thank you very much for your help. :)
>
>
> Peter Jamieson, am 09.05.2007 13:59:
>>> the columns I declared in the first line of the csv-file to the fields
>>> Word uses for mailmerge?
>>
>> You only need to map fields if you are using merge fields that rely on
>> mapping, such as ADDRESSBLOCK and GREETINGLINE, or if you want to use
>> mapping and use the standardlist of "Address Field" names with the "\m"
>> switch in the MERGEFIELD fields.
>>
>> Not sure about Word 2007 but in Word 2003 you can't assign to the name.
>> You can work around this by assigning one index to another, e.g. to
>> assign the Address field "City" to the first column in the data source in
>> VBA, you might use:
>>
>> Dim objMDFs As MappedDataFields
>> Set objMDFs = ActiveDocument.MailMerge.DataSource.MappedDataFields
>> objMDFs(wdCity).DataFieldIndex = 1
>> Set objMDFs = Nothing
>>
>> i.e. if you want to assign the data source fied called "Town" to the
>> mapped field "City", you will probably need to iterate through the
>> ActiveDocument.MailMerge.DataSource.DataFields collection looking for the
>> field whos ename is "Town", and use its index value to set the
>> MappedDataFields.DataFieldIndex.
>>
>> Peter Jamieson
>>
>> "b.schmidt" <shocker843[ at ]hotmail.com> wrote in message
>> news:%23qHD%23eikHHA.1992[ at ]TK2MSFTNGP05.phx.gbl...
>>> hi,
>>>
>>> I added a csv-file as DataSource to a Word Document (I'm using VSTO, C#
>>> and Word 2007), which worked fine. Now I was wondering, how I can map
>>> the columns I declared in the first line of the csv-file to the fields
>>> Word uses for mailmerge?
>>>
>>> I tried to use MappedDataFields, but whenever I tried to write to a
>>> MappedDataField.DataFieldName it tells me that this property is
>>> read-only?
>>>
>>> I'm a bit confused...
>>>
>>> best regards,
>>> Bernhard
>>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net