View Single Post
  #2   Report Post  
Vic Spainhower
 
Posts: n/a
Default

I was able to elimate the "Remote Server Unavailable ..." with the following
code replacement. However, now the WHERE clause in the OpenDataSource is
ignored.

Could someone tell me why?

TIA

Vic


**Code Follows **

Dim strLoginName As String
Dim strMyDocuments As String
Dim WordWasNotRunning As Boolean ' Flag For final word unload
Dim strDocument As String
Dim strWhereClause As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document

On Error GoTo ErrorHandler

strDocument = "CoverLetter.doc"
strLoginName = "Vic"
strMyDocuments = "C:\Client Databases\Hughes Supply\Word Docs\"

Set WordApp = CreateObject("Word.Application")
'WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open(strMyDocuments & "\" & strDocument)

With WordDoc
strWhereClause = "WHERE JobID = '" & frmMain.txtJobid & "'"
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\vic.HOME\My Documents\My Data
Sources\Hughes_Jobs vuCoverLetter.odc" _
, ConfirmConversions:=False _
, ReadOnly:=False _
, LinkToSource:=True, _
AddToRecentFiles:=False _
, PasswordDocument:="" _
, PasswordTemplate:="", _
WritePasswordDocument:="" _
, WritePasswordTemplate:="" _
, Revert:=False, _
format:=wdOpenFormatAuto _
, Connection:= _
"Provider=MSDASQL.1;Persist Security Info=True;" _
& "Extended Properties=""" _
& "DSN=HughesSupply;" _
& "Description=Hughes Supply Jobs;" _
& "UID=vic;APP=Microsoft Office XP;" _
& "WSID=VIC-XP;" _
& "DATABASE=Hughes_Jobs;" _
& "Trusted_Connection=Yes"";" _
& "Initial Catalog=Hughes_Jobs" _
, SQLStatement:="SELECT * FROM [vuCoverLetter]" _
, SQLStatement1:=strWhereClause, _
SubType:=wdMergeSubTypeOther

ActiveDocument.MailMerge.MainDocumentType = wdFormLetters

End With

WordApp.Visible = True
WordApp.Application.Activate
On Error Resume Next
Set WordApp = Nothing
Set WordDoc = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Number & Err.Description