Hiya,
I've got some VBA code that pulls some records from a database, throws them into a tab separated .txt file, and then sets up a mailmerge to that text file.
Works fantastically!
Except....
I've just been hunting for a glitch that occurred today. I've worked out that the file path contained the word 'where' in it.
eg "C:\Jobs\Timber
where missing\"
Code:
strPath = ActiveDocument.Path & "\MailMerge.txt"
ActiveDocument.MailMerge.OpenDataSource strPath, , , True, False
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
Any suggestion on how I can get around this?
I'm guessing this is because WHERE is an SQL reserved word...
If I manually do the mail merge, i get an SQL error. See image below.
I've tried to put ' or " at the start and finish of the strPath variable. No good.
The only work around is to rename the folder.
This isn't ideal - as if i go down this line, there are probably other SQL keywords that will cause problems.
Any suggestions for this unique situation?....
It is kind of a Microsoft Glitch / Bug...