By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

Filtering a textfile datasource for mailmerging in Word

P: 7
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?
Jan 6 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 487
Can you check somewhere you are assigning again for “wordDoc.MailMerge.DataSource.QueryString =”?
Jan 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.