-
shpkmom
AskWoody LoungerAugust 14, 2020 at 4:19 pm in reply to: Word 365 Mail Merge Problem re DDE connection error #2288686Ultimately what I am trying to do is connect a MS Query to a mail merge main document. The original code I had is here:
‘Open a blank document
Documents.Add documenttype:=wdNewBlankDocument
On Error GoTo Oops
‘Manually type the query and save
With Selection
.TypeText Text:=”XLODBC”
.TypeParagraph
.TypeText Text:=”1″
.TypeParagraph
.TypeText Text:=”DRIVER=SQL Server;SERVER=NAME;UID=NAME;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=01234;DATABASE=son_db”
.TypeParagraph
.TypeText Text:=”SELECT matter.mmatter, client.clname1, client.clname2, matter.mdesc1, matter.mdesc2, matter.mdesc3, matter.mclient, timekeep.tkinitb, matter.mprac, praccode.pdesc, udf.udvalue FROM son_db.dbo.client client, son_db.dbo.matter matter, son_db.dbo.praccode praccode, son_db.dbo.timekeep timekeep, son_db.dbo.udf udf, son_db.dbo.udfdef udfdef WHERE timekeep.tkinit = matter.mbillaty AND matter.mprac = praccode.pcode AND udfdef.udfindex = udf.udfindex AND udfdef.udtype = udf.udtype AND matter.mmatter = udf.udjoin AND matter.mclient = client.clnum AND ((matter.mstatus=’OP’) AND (udf.udtype=’MT’) AND (udf.udfindex=41) AND (matter.mmatter = ‘” & strvMatterNumber & “‘))”
End With
‘Save the query text
ActiveDocument.SaveAs FileName:=STRMACROFILES & “NMLabels.dqy”, fileformat:=wdFormatText, _
lockcomments:=False, Password:=””, addtorecentfiles:=False, WritePassword:=””, ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, savenativepictureformat:=False, SaveFormsData:=False, saveasAOCELetter:=False, _
Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False, LineEnding:=wdCRLF
ActiveDocument.Close
Application.ScreenUpdating = False
‘Open the template and set as main document
Documents.Add Template:=STRMRTEMPLATES & “Open NEW Matter Labels.dotx”, newtemplate:=False
Set MainDoc = ActiveDocument
ActiveDocument.MailMerge.OpenDataSource Name:=STRMACROFILES & “NMLabels.dqy”, ConfirmConversions:=False
Since we switched to Word 365, when this macro is run it has a message at the bottom saying connecting to MS Query, it takes a long time and then returns a DDE error. I would like to know how to fix it so that I can still attach this query to a mail merge document without the error.
Does anyone have any ideas?
-
shpkmom
AskWoody LoungerAugust 10, 2020 at 11:37 am in reply to: Word 365 Mail Merge Problem re DDE connection error #2287618Thanks — that’s helpful
Do you have some general code you could post that would help guide me in the right direction by any chance? I am really struggling with this …
Thank you again!
-
shpkmom
AskWoody LoungerSo I changed the coding to use OLEDB connection but can’t get the SQL query small enough to be less than 255 characters. Please let me know if I’m on the right path and if there is something else I can do?
strDatabase = “DRIVER=SQL Server;SERVER=…;DATABASE=son_db”
strSQL = “SELECT * FROM son_db.dbo.client client, son_db.dbo.matter matter, son_db.dbo.praccode praccode, son_db.dbo.timekeep timekeep, son_db.dbo.udf udf, son_db.dbo.udfdef udfdefWHERE timekeep.tkinit = matter.mbillaty AND matter.mprac = praccode.pcode AND udfdef.udfindex = udf.udfindex”
strSQL2 = “AND udfdef.udtype = udf.udtype AND matter.mmatter = udf.udjoin AND matter.mclient = client.clnum AND ((matter.mstatus=’OP’) AND (udf.udtype=’MT’) AND (udf.udfindex=41) AND (matter.mmatter = ‘” & strvMatterNumber & “‘))”
ActiveDocument.MailMerge.OpenDataSource Name:=strDatabase, SQLStatement:=strSQL, SQLStatement1:=strSQL2
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
6 hours, 35 minutes ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
7 hours ago -
Asking Again here (New User and Fast change only backups)
by
thymej
17 hours, 56 minutes ago -
How much I spent on the Mac mini
by
Will Fastie
7 hours, 23 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
24 minutes ago -
Spring cleanup — 2025
by
Deanna McElveen
23 hours, 48 minutes ago -
Setting up Windows 11
by
Susan Bradley
2 hours, 10 minutes ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
19 hours, 16 minutes ago -
Powershell version?
by
CWBillow
20 hours, 8 minutes ago -
SendTom Toys
by
CWBillow
4 hours, 25 minutes ago -
Add shortcut to taskbar?
by
CWBillow
1 day ago -
Sycophancy in GPT-4o: What happened
by
Alex5723
1 day, 16 hours ago -
How can I install Skype on Windows 7?
by
Help
1 day, 15 hours ago -
Logitech MK850 Keyboard issues
by
Rush2112
22 hours, 4 minutes ago -
We live in a simulation
by
Alex5723
2 days, 6 hours ago -
Netplwiz not working
by
RetiredGeek
1 day, 17 hours ago -
Windows 11 24H2 is broadly available
by
Alex5723
2 days, 19 hours ago -
Microsoft is killing Authenticator
by
Alex5723
1 day, 6 hours ago -
Downloads folder location
by
CWBillow
3 days, 1 hour ago -
Remove a User from Login screen
by
CWBillow
1 day, 21 hours ago -
TikTok fined €530 million for sending European user data to China
by
Nibbled To Death By Ducks
2 days, 16 hours ago -
Microsoft Speech Recognition Service Error Code 1002
by
stanhutchings
2 days, 16 hours ago -
Is it a bug or is it expected?
by
Susan Bradley
18 hours, 43 minutes ago -
Image for Windows TBwinRE image not enough space on target location
by
bobolink
2 days, 15 hours ago -
Start menu jump lists for some apps might not work as expected on Windows 10
by
Susan Bradley
1 day, 15 hours ago -
Malicious Go Modules disk-wiping malware
by
Alex5723
3 days, 5 hours ago -
Multiple Partitions?
by
CWBillow
3 days, 6 hours ago -
World Passkey Day 2025
by
Alex5723
3 hours, 1 minute ago -
Add serial device in Windows 11
by
Theodore Dawson
4 days, 14 hours ago -
Windows 11 users reportedly losing data due forced BitLocker encryption
by
Alex5723
2 days, 15 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.