View Single Post
 
Old 08-31-2017, 01:54 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,366
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To get the SQL query string, open up the document and connect it to the data source for a mailmerge if that hasn't already been done. Having done that, go to Mailings|Edit Recipient List>Filter and apply the requisite filter to the problematic field. The following macro will then tell you, in turn, what are the: Data Source Name; Connect String; and Query String. It's the last of these you need to incorporate into your code - be careful with the direction of any quote characters. You could, of course, output any of these to the end of the document so you can cut & paste any parts you need into your code.
Code:
Sub Test()
With ActiveDocument.MailMerge
  If .MainDocumentType <> wdNotAMergeDocument Then
    MsgBox "Mail Merge Data Source Name:" & vbCr & .DataSource.Name
    MsgBox "Mail Merge Connect String:" & vbCr & .DataSource.ConnectString
    MsgBox "Mail Merge Query String:" & vbCr & .DataSource.QueryString
  Else
    MsgBox "Not A Merge Document"
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote