Filtering a textfile datasource for mailmerging in Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bogorman
    New Member
    • Aug 2007
    • 7

    #1

    Filtering a textfile datasource for mailmerging in Word

    I am using the following coding:

    Dim strWordDocFile As System.String = Me.txtLetter.Te xt
    Dim WordDocFile As New System.IO.FileI nfo(strWordDocF ile)
    Dim Msg As String
    Dim strDatafile As String
    Dim strQueryString As String
    Dim strAlphFldName As String
    Dim strFilterValue As String


    strDatafile = "c:\LobbyMail\L ordsList.txt"




    ' See if the file specified exists
    If (WordDocFile.Ex ists) Then


    Dim wordApplication As New Microsoft.Offic e.Interop.Word. Application
    Dim wordDoc As Microsoft.Offic e.Interop.Word. Document = wordApplication .Documents.Open (LetterName, , True, False)

    strAlphFldName = "Alph"
    strFilterValue = "B"
    strQueryString = "((" & """" & strAlphFldName & _
    """" & " = '" & strFilterValue & "'))"


    wordDoc.MailMer ge.OpenDataSour ce(strDatafile)
    wordDoc.MailMer ge.Destination = WdMailMergeDest ination.wdSendT oPrinter
    wordDoc.MailMer ge.DataSource.Q ueryString = "select * from " & strDatafile & " WHERE " & strQueryString


    The problem is in defining wordDoc.MailMer ge.DataSource.Q ueryString
    When I place a breakpoint about this point in the coding, its value is :

    "SELECT * FROM C:\LobbyMail\Lo rdsList.txt"

    so the where clause is left off. I assume it is a syntax problem.

    Can anyone suggest how I can overcome this?
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    Can you check somewhere you are assigning again for “wordDoc.MailMe rge.DataSource. QueryString =”?

    Comment

    Working...