Log in

View Full Version : [SOLVED:] Mailmerge sql query string output to a variable



charliew001
08-27-2013, 03:22 PM
Hi all,

I am creating a mail merge macro in VBA for microsoft word 2010, and I would like to know how to output a query string into a variable. So ideally, it would be something like below. However, x always seem to equal zero. I am trying to get the number of distinct records in a particular field and was hoping to be able to use the sql querie to get that number. Any help is appreciated. The records are from an excel file.



Dim x as long
With ActiveDocument.mailmerge
x = Clng(.QueryString = "Select COUNT(DISTINCT [Field]) FROM [Table])"