merging fields from Outlook Contacts

J

J.R. Winder

Hi-

My dev group has developed and addin for Outlook 07 that enables Outlook
'Contact'
fields to be merged into MS Word 07 templates. The addin works fine however
Word seems to be including a leading space for the second line in the
Outlook Contact BusinessAddress field.

This is an example of how the fields are setup in the Word Template:
<FullName>
<CompanyName>
<BusinessAddressStreet>
<BusinessAddressCity>, <BusinessAddressState> <BusinessAddressPostalCode>

....and this is an example of how the data looks once the fields are merged
into the Word doc:
John Doe
John Does Landscaping
55 Main Street
Unit 4
Portsmouth, NH 03801

Through testing we've been able to determin that Outlook is passing the
<BusinessAddressStreet> field to Word properly (no leading space for line
2), yet for some reason Word includes the leading space for line 2 when
resolving the field data.

Any thoughts on how to make Word behave so there is no leading space when an
address filed has multiple lines for a street address?

Thanks
JR
 
D

Doug Robbins - Word MVP

Probably something to do with the new line feed translation from Outlook to
Word.

Try using the VBA Replace() function to replace Chr(10) with nothing.

In case it is not a Chr(10), select the space in the address and run

MsgBox Asc(Selection)

and see what numeral it returns. Then use that inside the () of Chr() in
the Replace function.

--
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
 
P

Peter Jamieson

Since inserting the Business_Address_Street using a regular { MERGEFIELD }
field works OK here, my guess is that your addin is assigning values from
the MailMerge.DataSource object to Document variables (or perhaps getting
the Outlook data some other way altogether), and that you are inserting the
results of those variables using { DOCVARIABLE } fields.

If so, in that case you do get something that looks to all intents and
purposes like a space at the beginning of line 2 of the address. If it was
actually a space, you'd see the usual dot when you displayed special
characters (pargraph marks etc.)

It seems to result from the fact that the string from outlook contains CRLF
(13,10) sequences at the end of the line, whereas Word only really wants a
CR (13). So if you strip the LFs out of the string, then assign it to the
Document variable, you may be OK. But I can't say I've explored any further
than to establish that that does work here in simple cases.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top