I am using the following coding:
Dim strWordDocFile As System.String = Me.txtLetter.Text
Dim WordDocFile As New System.IO.FileInfo(strWordDocFile)
Dim Msg As String
Dim strDatafile As String
Dim strQueryString As String
Dim strAlphFldName As String
Dim strFilterValue As String
strDatafile = "c:\LobbyMail\LordsList.txt"
' See if the file specified exists
If (WordDocFile.Exists) Then
Dim wordApplication As New Microsoft.Office.Interop.Word.Application
Dim wordDoc As Microsoft.Office.Interop.Word.Document = wordApplication.Documents.Open(LetterName, , True, False)
strAlphFldName = "Alph"
strFilterValue = "B"
strQueryString = "((" & """" & strAlphFldName & _
"""" & " = '" & strFilterValue & "'))"
wordDoc.MailMerge.OpenDataSource(strDatafile)
wordDoc.MailMerge.Destination = WdMailMergeDestination.wdSendToPrinter
wordDoc.MailMerge.DataSource.QueryString = "select * from " & strDatafile & " WHERE " & strQueryString
The problem is in defining wordDoc.MailMerge.DataSource.QueryString
When I place a breakpoint about this point in the coding, its value is :
"SELECT * FROM C:\LobbyMail\LordsList.txt"
so the where clause is left off. I assume it is a syntax problem.
Can anyone suggest how I can overcome this?