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 / April 2004

Tip: Looking for answers? Try searching our database.

need help with mail merge vba code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee Rouse - 19 Apr 2004 15:38 GMT
Hello,

I've been tweaking the code below to mail merge from Access 2000 to a
Word doc.

Two issues have come up.
1. The Code does not allow null values in any of the fields. Could
someone suggest what code to use so the function doesn't get hung up
on one or more fields? Please be specific- I know just enough about
vba to be dangerous to myself!

2.Data is merged with a .dot template file. When the data is merged, I
want the data to be merged with a new .doc, so that users don't
accidently save changes to the template. As it is now, the data is
merged into the .dot file. Can anyone help on this?

Thanks in advance,

Lee

Option Compare Database

Public Function CreateWordLetter(strDocPath As String)

  'if no path is passed to function, exit - no further
  'need to do anything
 
  If IsNull(strDocPath) Or strDocPath = "" Then
     Exit Function
  End If

  Dim dbs As Database
  Dim objWord As Object
  Set dbs = CurrentDb
 
  'create reference to Word Object
 
  Set objWord = CreateObject("Word.Application")
 
  'Word Object is created
 
 
  With objWord
      .Visible = True
      .Documents.Open (strDocPath)

      'move to each bookmark, and insert text.
     
     
      .activedocument.Bookmarks("FirstLastName").Select
      .Selection.Text = (CStr(Forms![frmmergeIFSP]![Name]))
           
       .activedocument.Bookmarks("ParentsGuardian").Select
      .Selection.Text =
(CStr(Forms![frmmergeIFSP]![ParentsGuardian]))
             
       .activedocument.Bookmarks("ChildSSN").Select
      .Selection.Text = (CStr(Forms![frmmergeIFSP]![childssn1]))
                       
  End With
'release all objects
 
  Set dbs = Nothing
 

End Function
Cindy M  -WordMVP- - 21 Apr 2004 15:37 GMT
Hi Lee,

> I've been tweaking the code below to mail merge from Access 2000 to a
> Word doc.
[quoted text clipped - 5 lines]
> vba to be dangerous to myself!
>  
Yeah, I remember this one. You need to do something like this:
   txtName.Value & ""

so that an empty string is passed for fields with a Null value.

> 2.Data is merged with a .dot template file. When the data is merged, I
> want the data to be merged with a new .doc, so that users don't
> accidently save changes to the template. As it is now, the data is
> merged into the .dot file. Can anyone help on this?

Use the .Add instead of the .Open method on the template (equivalent of
File/New in the UI). This will create a new document, based on the
template.

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 :-)

Rate this thread:






 
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.