View Single Post
 
Old 08-31-2017, 08:26 AM
vincenzo345 vincenzo345 is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Aug 2017
Posts: 13
vincenzo345 is on a distinguished road
Default

You've been a great help but im still having issues with this.

Code:
 
Dim doc As String
 
doc = "C:\MERGE\" & Environ("USERNAME") & "\word.txt"
 
  ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
    ActiveDocument.MailMerge.OpenDataSource Name:=doc, _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, sqlstatement:="SELECT * FROM doc WHERE [M_2] IS NOT NULL ", SubType:=wdMergeSubTypeOther
 
      With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
I was able to identify the field name that im looking for as being M_2.

If I use SELECT * FROM doc WHERE M_2 IS NOT NULL then the file will still merge but It doesnt remove the empty row.

If I use SELECT * FROM doc WHERE [M_2] IS NOT NULL then I get a "Run-Time Error 5922. Word was unable to open the data source."

Im not sure what im doing wrong. I also tried using 'M_2' instead of [M_2].


any ideas on what im messing up here?
Reply With Quote