View Single Post
  #4   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 Peter, thanks for your ongoing help.

error 462 "Remote server does not exists or it is unvailable"

Reading the ms support page I believe it is to do with my referencing of
variables, but can't work out exactly what. Code is now as follows:

Function fnMergeIt(strDoc As String, strTbl As String)
On Error GoTo Err_fnMergeIt


Dim objApp As Object
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)
'Debug.Print strDoc

Set objApp = CreateObject("Word.Document")

Set objWord = Word.Documents.Open(strDoc, , True)

' 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

Exit_fnMergeIt:
Set objWord = Nothing
Set objApp = Nothing
Exit Function

Err_fnMergeIt:
MsgBox "fnMergeIt: " & Err.Number & " - " & Err.Description
Resume Exit_fnMergeIt

End Function

I believe it is to do with my use of the 'word' object/variables but my lack
of familiarity with word vba isn't helping.

Peter Jamieson wrote:
At what point is it going wrong?


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