Microsoft Word Mail Merge SQL Server

Sub ConfigureMailMerge(clientId As Long, dsnFile As String, viewName As String)

Debug.Print “Call ConfigureMailMerge(” & Str(clientId) & “, ” & dsnFile & “, ” & viewName & “)”


Dim sql As String
‘sql = “SELECT * FROM ” & viewName & ” WHERE clientid=” & Trim(Str(clientId)) & “”
sql = “SELECT * FROM “”” & viewName & “”” WHERE clientid=” & Trim(Str(clientId)) & “”
‘sql = “SELECT * FROM ” & MYVIEW & ” WHERE clientid='” & Trim(Str(clientId)) & “‘”
Debug.Print sql

Dim sConn As String
sConn = “FILEDSN=” & dsnFile & “;”

ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource _
Name:=dsnFile, _
SQLStatement:=sql

Debug.Print “Datasource Record Count = ” & ActiveDocument.MailMerge.DataSource.RecordCount

Debug.Print “Return ConfigureMailMerge”

End Sub