View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
darren via OfficeKB.com
 
Posts: n/a
Default Open mail merge doc as read only

Hi

Totally new to word vba, I have put together the following code in Access but
wish the word doc to opened as read only to protect the original text.

Function fnMergeIt(strDoc As String, strTbl As String)


Dim objWord As Word.Document
Dim strConnection As String
Dim path As String
Dim strDataDir As String

strConnection = "DSN=MS Access Database;DBQ=" & CurrentProject.FullName &
" ;FIL=MS Access;"

strDoc = Chr$(34) & CurrentProject.path & "\" & strDoc & Chr$(34)

Set objWord = GetObject(strDoc, "Word.Document")

' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:=CurrentProject.FullName, _
LinkToSource:=True, _
Connection:=strConnection, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [" & strTbl & "]"

objWord.MailMerge.ViewMailMergeFieldCodes = False

' Make Word visible.
objWord.Application.Visible = True

Set objWord = Nothing

End Function

Thanks

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...merge/200604/1