Match fields in Address block

B

Bob S

I am using Office 2003 on XP Pro.

I want to run a mail merge using an existing document. When I get to Step 3
of 6 and click the match fields button, I see them all matched up with a
great number of fields to choose from in the pull down lists.

Unfortunately, when I select "select from Outlook contacts", choose the
contact folder, and press OK, I find that most of the fields are NOT matched
and that there are only a few options to choose from - namely: Icon, File
as, Company, Original Display Name, Home phone, Home Address, Display Name,
and (not matched).

How do I get the other choices back?

Thank you much for your help.
 
B

Bob S

Thanks Graham. I did get access to all of my fields for matching by starting
the merge in OL 2003. However, I have a couple of further questions.

1. I ran it several times and each time, it kept all of the fields matched
EXCEPT postal code. Each time I had to manually match it to "Zip/postal
code" at the very bottom of the list of fields to match. How can I get this
to pernamently match?

2. I have 9 addresses that require 4 lines. 5 of them look nice. The
other 4 have a gap (empty line) between lines 3 and 4. What can be done
about this?

Thanks for your help.
 
G

Graham Mayor

Reinsert the Post code field into the template and save the template again.
The missing line is caused by missing field information in the address. You
can insert the address using conditional fields to place the address lines
and their associated line feeds eg

{IF {Mergefield Company} <> "" "{Mergefield Company}
"}put the next address field here using the same format as above.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
B

Bob S

Graham, I do not think I understand all that you are saying.

I think I have reinserted the Postal Code field into the template and saved
it again. And still it does not keep the Postal Code matched. Here are
some particulars.

I saved it as a regular file. Do I need to do something special to save it
as a template?
When I click the button to "Match Fields", it has always been showing
"Postal Code" under the "Required Information" Category in the left column
of the dialog box. However, while most of the fields in the boxes on the
right show a definite match, the Postal Code box still says (not matched).
Even after I change it to Zip/Postal Code and then save it and start over
with an existing document.

I would like to come back to the other question after I understand you on
this one.
 
G

Graham Mayor

I see what you mean, but I have not been able to reproduce the problem here.
The matched field holds.
See if my other web page on merges helps make things easier for you -
http://www.gmayor.com/mail_merge_labels_with_word_xp.htm. Although it uses
labels as an example (as these are the most complicated) the information is
applicable to all types of merge.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
B

Bob S

Graham,
I read your other web page and also the one by Suzanne Barnhill that you
reference on your page. I also added the buttons on the merge toolbar that
both of you recommended. Unfortunately they did not help my problems.

Revised questions:
1. Concerning Matched Fields holding, I am using the new Unicode format for
my OL pst file. Could that be the problem?
2. Two of my addresses seem almost identical, with 2 lines in the street
address and the other fields (city, state, zip, & country) all filled. Yet
one has a blank line between the third and fourth line. Any thoughts?
 
G

Graham Mayor

Bob said:
Graham,
I read your other web page and also the one by Suzanne Barnhill that
you reference on your page. I also added the buttons on the merge
toolbar that both of you recommended. Unfortunately they did not
help my problems.

Revised questions:
1. Concerning Matched Fields holding, I am using the new Unicode
format for my OL pst file. Could that be the problem?

That's what I use too - so this is not the problem.
2. Two of my addresses seem almost identical, with 2 lines in the
street address and the other fields (city, state, zip, & country) all
filled. Yet one has a blank line between the third and fourth line.
Any thoughts?

The address with the blank line either has an empty field or has a line feed
in a required field. You can insert a conditional field to correct for the
former, but the latter will require the record to be edited.

{IF {Mergefield Fieldname1} <> "" "{Mergefield Fieldname1}
"{IF {Mergefield Fieldname2} <> "" "{Mergefield Fieldname2}
" etc

The above demonstrates the use of conditional field to insert the data *and
the following line feed* only when the field is not empty
If you use the merge toolbar tools to insert exactly the fields you want as
described in the web page, the field matching issue should not cause a
problem.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
 
B

Bob S

I would like to ask 2 more related questions Graham, if you do not mind.
1. When I do a mail-merge (for labels) from OL, I use an existing document
for the document file. If I open that existing file within Word directly,
and then check the field matching, I find that all of the fields are
matched. If I go on with a mail merge either from a start in OL or a start
in MS Word, it is then that I find that the zip/postal code is NO LONGER
matched. Does that give any clue as to where the problem is?

2. If one starts the mail merge from OL (as you suggest), is it possible to
record a macro to do the task?

Thank you for your help.
 
G

Graham Mayor

Bob said:
I would like to ask 2 more related questions Graham, if you do not
mind.
1. When I do a mail-merge (for labels) from OL, I use an existing
document for the document file. If I open that existing file within
Word directly, and then check the field matching, I find that all of
the fields are matched. If I go on with a mail merge either from a
start in OL or a start in MS Word, it is then that I find that the
zip/postal code is NO LONGER matched. Does that give any clue as to
where the problem is?

The problem here is that you are using a merge source document that was
produced by a different connection method to the way Office now handles the
interface between Word and its data. You need either to rebuild your merge
document starting from Outlook so it has the correct information, or use the
earlier method of connection which is still available - albeit not by
default. The information required to set the connection methods is described
in the Excel data section of
http://www.gmayor.com/mail_merge_labels_with_word_xp.htm
2. If one starts the mail merge from OL (as you suggest), is it
possible to record a macro to do the task?

You would have to ask about Outlook vba programming in an Outlook ng.
Thank you for your help.

If only it was helping :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
 
P

Peter Jamieson

The problem here is, IMO, that when you initiate your merge from Outlook,
Outlook
a. creates a Word document and exports its data to that document
b. (re)specifies that document as the data source for the merge.

If you do not specify a data source document name in OL, OL will create a
new "temp" file, and connect to that. But even if you specify a "permanent"
Word document as the place to put the data, Outlook still does (b), and the
problem with that is that Word then discards - as far as I can tell -
c. any sort or filter coditions you may have specified in Word (OK, not too
important since you can filter in OL)
d. any "match fields" stuff you have set up.

In addition, in Word 2003, you also get a stream of questions about SQL
security, overwriting the existing data source etc. You might also get
questions about the data source not existing if

What's more, because Outlook opens the file /then/ does a reconnection job,
as far as I can see, writing an AutoOpen macro in your document would not
help because it would be executed too early in the process and its effects
would be overridden by Outlook's actions.

So I suspect that in order to restore the "Match fields" you need easily,
you would have to write a small macro to do it and attach it to a toolbar
button. Unfortunately Word does not seem to record Match fields operations,
and the code is slightly more tortuous than I would like, but e.g.

Sub MapPostalCode()

Dim oMDF As MappedDataField

With ActveDocument.MailMerge.DataSource
For Each oMDF In .MappedDataFields
If oMDF.Name = "Postal Code" Then
oMDF.DataFieldIndex = .DataFields("ZIPPostal_Code").Index
End If
Next
End With

End Sub

For a slightly more automated solution I suppose you could put the above
code inside the appropriate Mailmerge Event, but I haven't tried it and
since it's more complicated please ask if you need more info. on how to do
it.

As far as recording macros is concerned, although you can write VBA macros
for OL, OL has no facilty for recoording them. I am reasonably sure that it
would be possible to write an Outlook macro to do what you wanted but it's
non-trivial and I don't have suitable code on offer.
 
B

Bob S

Thank you very much Peter for the macro. Since I am totally new to VBA, I
would appreciate it a great deal if you could show me how to put the code of
that macro inside the Mailmerge Event: "Merge to New Document". Since I
have that icon on my mail-merge toolbar, it would make the automation much
easier. Thanks again for your help.
Bob
 
P

Peter Jamieson

Hi Bob,

OK, when I was talking about events, I meant something else which involves
knowing even more VBA (though not a whole lot more).

You can modify the action of the existing button by using the following code
instead:

Sub MailMergeToDoc()
Dim oMDF As MappedDataField

With ActveDocument.MailMerge.DataSource
For Each oMDF In .MappedDataFields
If oMDF.Name = "Postal Code" Then
oMDF.DataFieldIndex = .DataFields("ZIPPostal_Code").Index
End If
Next
End With

' call the built-in routine

WordBasic.MailMergeToDoc

End Sub

At least, I believe that's the case, but I'm not a VBA expert.

The effect of this depends on where you put it - if you put it in a module
in one document, it should only have an affect when you (or Outlook) load(s)
that document. If you put it in the normal.dot template, it will affect
every merge to a document that you do, and will fail if the merge doc. does
not have the fields named in the macro.

I'm not a big fan of modifying the behaviour of existing menu options and
toolbar buttons - if you are doing it on behalf of other people, it means
they no longer see the default behaviour and things can get even more
confusing. Even if you are doing it just for yourself you may forget how you
did a certain thing. So typically I would suggest adding a new button,
preferably on a new toolbar, and attaching the macro to that (just have a
look at Tools|Customize and you should be able to work out how to do it).
 
B

Bob S

Hi Peter,

I agree that I do not want to change a standard button, since I will likely
want to use it for its normal function in the future. Actually, I still need
a couple more baby steps.

I copied the macro into the VBA editor (Tools/Macro/Macros/Create). Then I
started the merge from OL and got to Word with the Labels source document on
the screen. Then I ran the macro (Tools/Macro/Macros/highlighted
MergeToDoc/Run). It gave me a runtime error of "424 Object required". In
the debugger, it highlighted the following line:
"With ActiveDocument.MailMerge.DataSource"

Could you tell me what I missed? Thanks for these baby steps.
Bob
 
P

Peter Jamieson

Hi Bob,

Sorry about this as I've been looking at this again and realised that the
macro only works if the field has been mapped previously, which isn't the
case in your situation. In fact there seems to be no way to add a member to
the MappedDataFields collection. So it doesn't work, and right now I can't
see a way to make it do so. So your only optoin looks to be to use the Match
fields icon in the Mailmerge toolbar to map the field manually.
 
B

Bob S

Hi Peter,

What a bummer. I have thought of another approach which relates to another
problem I am having with a functionality lost (shared folders)going from OL
2000 to OL 2003. Let me ask your opinion on something I am considering.

Do you happen to know whether I would run into any problems if I uninstalled
Word 2003 and OL 2003 and reinstalled Word 2000 and OL 2000. I want to keep
Powerpoint 2003 because of some new features it has. While I like some of
the new features of Word and OL, I miss the lost functionality more than the
new features.

Question: Would I mess anything up by doing an uninstall 2003 and reinstall
2000 to go back toWord 2000 and OL 2000 but keep Powerpoint 2003?

Thanks for your advice.
Bob
 
P

Peter Jamieson

Question: Would I mess anything up by doing an uninstall 2003 and
reinstall
2000 to go back toWord 2000 and OL 2000 but keep Powerpoint 2003?

Much as I'd like to help I don't have much experience in this area, and you
should probably try to check in one of the more general groups.

I would guess that you will be OK, but
a. if there is an File|Send to e-mal option in Powerpoint you may find it
does not work as you hope (cf. Word & Outlook versions need to be the same
for the full functionality to be available)
b. you will probably be left with the later (2003) versions of shared
components such as data libraries ("the MDAC"). In the case of the data
libraries in general you are probably better off with the latest version
anyway. I'm not sure what would happen with any shared Applets.
 
B

Bob S

Thanks Peter. You have been very helpful.

Peter Jamieson said:
Much as I'd like to help I don't have much experience in this area, and you
should probably try to check in one of the more general groups.

I would guess that you will be OK, but
a. if there is an File|Send to e-mal option in Powerpoint you may find it
does not work as you hope (cf. Word & Outlook versions need to be the same
for the full functionality to be available)
b. you will probably be left with the later (2003) versions of shared
components such as data libraries ("the MDAC"). In the case of the data
libraries in general you are probably better off with the latest version
anyway. I'm not sure what would happen with any shared Applets.

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

to in is most all
 
P

Peter Jamieson

Bob,

You didn't post an e-mail address but maybe you're still scanning this
group...

I thought about this some more and realised that it might be possible to
write a macro to replace the field name exported by Outlook with one that
Word will recognise. I've only run simple tests etc.

Here's some VBA code for that. You can find more info on how to use it on
the Word MVP site at

http://word.mvps.org

NB, somewhere earlier in this thread I said that Outlook exports the data as
a Word document. But what it actually does is export it as a Unicode format
text file with a ".doc" extension.

Sub ModifyZipFieldName()

' Macro by PJ Jamieson, March 2004
' This macro looks for a field name called "ZIP/Postal Code"
' in the header record of a mail merge data source and modifies
' the name so that Word automatically maps its ZIP/Postal code
' to the field.
' Written for use with Word 2003/Outlook 2003, but it may work
' in earlier versions
' Requires the "Microsoft Scripting Runtime" object library:
' You will need to use the VBA Editor menu command
' Tools|References to add a reference to this library

' This macro is intended to be used when a merge is initiated
' from Outlook. In that case, I believe the following assumptions
' can be made:
' The merge data file is a Unicode format text file
' (notice that by default it has a .doc extension)
' Outlook reconnects to the data source and removes any
' sort/filter options you may have defined

' The macro also assumes that it is OK to create/overwrite a
' file with the same name as the data source + ".tmp"

Dim oFileSystemObject As Scripting.FileSystemObject
Dim oSourceStream As Scripting.TextStream
Dim oDestStream As Scripting.TextStream
Dim sHeaderRecord As String
Dim sMergeDataSourceName As String
Dim vMergeType As WdMailMergeMainDocType
Dim vMergeDestination As WdMailMergeDestination
On Error GoTo finish

With ActiveDocument.MailMerge
If .MainDocumentType = wdNotAMergeDocument Then
MsgBox "This document is not a mail merge main document"
Else
' Save merge type and destination
vMergeType = .MainDocumentType
vMergeDestination = .Destination
sMergeDataSourceName = .DataSource.Name
.MainDocumentType = wdNotAMergeDocument

Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
With oFileSystemObject
' This assumes the file is Unicode format (I think)
Set oSourceStream = .OpenTextFile( _
FileName:=sMergeDataSourceName, _
IOMode:=ForReading, _
Create:=False, _
Format:=TristateTrue)

' Verify that the required string exists before going any further
sHeaderRecord = oSourceStream.ReadLine
If InStr(1, sHeaderRecord, "ZIP/Postal Code") = 0 Then
MsgBox "Could not find the field name 'ZIP/Postal Code'" & _
"in the merge data source." & _
vbCrLf & "You will need to match fields manually"
oSourceStream.Close
Set oSourceStream = Nothing
Else
' create the output file
Set oDestStream = .CreateTextFile( _
FileName:=sMergeDataSourceName + ".tmp", _
overwrite:=True, _
unicode:=True)

' Make the substitution. The field names "ZIP" and "Postcode"
' seem to be recognised automatically by Word

oDestStream.WriteLine _
Text:=Replace(sHeaderRecord, "ZIP/Postal Code", "ZIP")

' copy the rest of the file
Do Until oSourceStream.AtEndOfStream
oDestStream.WriteLine Text:=oSourceStream.ReadLine
Loop

' Close everything and replace the old file by the new one
oDestStream.Close
Set oDestStream = Nothing
oSourceStream.Close
Set oSourceStream = Nothing
oFileSystemObject.DeleteFile _
filespec:=sMergeDataSourceName, _
force:=True
oFileSystemObject.MoveFile _
Source:=sMergeDataSourceName + ".tmp", _
Destination:=sMergeDataSourceName
End If
End With
Set oFileSystemObject = Nothing
End If

' Set up the mail merge data source etc. again
' You may find that you need to save and restore
' other settings
.OpenDataSource Name:=sMergeDataSourceName
.MainDocumentType = vMergeType
.Destination = vMergeDestination

End With

Exit Sub
finish:
Close #1
MsgBox "Error " & Err.Number & _
" when trying to modify the ZIP field name: " & _
vbCrLf & Err.Description
Err.Clear
On Error Resume Next
Set oSourceStream = Nothing
Set oDestStream = Nothing
Set oFileSystemObject = Nothing
End Sub
 

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