Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2004

Tip: Looking for answers? Try searching our database.

Any debugger help?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matthew Chan - 11 Feb 2004 09:18 GMT
I have find the following code to overwrite the mailmerge field with the
recordset value. but find error occur while there is null field of recordset
value.

loWordApp.Documents.Add (asMergeDoc) 'Add an instance For Each record
            Set loDoc = loWordApp.ActiveDocument 'Utilize newest instance
           loDoc.Activate
            Do Until aors.EOF

           ReDim lsaFldNames(loDoc.MailMerge.Fields.Count)

         Debug.Print loDoc.Fields.Item(1).Code

               For Nc = 1 To loDoc.MailMerge.Fields.Count
                   lsFieldName =
Trim(Right(loDoc.MailMerge.Fields(Nc).Code,
Len(loDoc.MailMerge.Fields(Nc).Code) - 11))
                   lsaFldNames(Nc) = lsFieldName
               Next Nc

               For Nc = 1 To loDoc.MailMerge.Fields.Count
                   loDoc.MailMerge.Fields(1).Select

                   lbmatched = False

                   For llmatch = 0 To UBound(larrTTXField)
                       If larrTTXField(llmatch) = lsaFldNames(Nc) Then
                           lbmatched = True
                           Exit For
                       End If
                   Next

                   If lbmatched = True Then
                         If Trim(aors(lsaFldNames(Nc))) = "" Then
                         Else
                         loGlobVar.Selection.TypeText
Trim(aors(lsaFldNames(Nc)))
                         End If

                   End If
               Next Nc

                   loDoc.MailMerge.Destination = wdSendToNewDocument
                  loDoc.SaveAs asOutputFullPathFilename

               aors.MoveNext
        Loop
           aors.Close
           loWordApp.Quit
Cindy M  -WordMVP- - 11 Feb 2004 20:19 GMT
Hi Matthew,

> I have find the following code to overwrite the mailmerge field with the
> recordset value. but find error occur while there is null field of recordset
> value.

Well, leaving aside the question whether merge fields are really meant for
this sort of thing (they're NOT!), which line of the code you posted is
causing the error?

Generally, since Word works entirely with strings, for an null string value
you can append and empty string:  & ""

Not sure if this is the answer you're looking for, but perhaps it is :-)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.