D
darren via OfficeKB.com
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
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