Controlling Word Mail Merge with VBA

  • I'm trying to create some Excel code to eventually produce a mail merge document in Word.


    The code works fine, and a mail merged document comes out of other end, but, my problem is that I don't want to return all records in the range that I've defined in the Excel 'table'. This works fine if doing the process manually in Word using the 'select recipients' mail merge option but I can't get the code into Excel. All help I've come across suggests that a SQL statement is the answer, but whatever I put in I still get all rows returned.


    An extract from my code (edited to make a bit easer to read) is below



    Note that NamedRange is a range named on a worksheet, and FieldName is the name of one of my Columns


    Any suggestions would be much appreciated.

  • Re: Controlling Word Mail Merge with VBA


    An update:


    In essence, my code is correct. After much testing, I have discovered the problem is in my data; the field heading (shown as FieldName) in the attached code, in real life, has a space in it (e.g. 'Field Name') so my problem really is "How do I get a space into the name of a field in my WHERE condition?"

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!