mail merge access 2013, not access 2000
there docs mail merge old versions of access: https://support.microsoft.com/en-us/kb/209976
but unable find docs or advice 2013 versions.
aim: have button in ms access triggers mail merge based on selected data.
problem:
while mail merge works fine if hand, , export data before doing merge. fails if try create live link. tables office 365 style share point lists - looks causing time out problems , locking problems. suspect maybe need export before can merge.
access 2000 style mail merge code:
function mergeit() dim objword word.document set objword = getobject("c:\mymerge.doc", "word.document") ' make word visible. objword.application.visible = true ' set mail merge data source northwind database. objword.mailmerge.opendatasource _ name:="c:\program files\microsoft " & _ "office\office\samples\northwind.mdb", _ linktosource:=true, _ connection:="table customers", _ sqlstatement:="select * [customers]" ' execute mail merge. objword.mailmerge.execute end function
export xls run mail merge.
private sub command53_click() docmd.outputto acoutputquery, "mail merge query name", acformatxls, "temp export mail merge file.xls" set objword = getobject("path mail merge file.docx", "word.document") ' objword.application.visible = true objword.mailmerge.opendatasource _ name:="temp export mail merge file.xls", _ readonly:=true, _ sqlstatement:="select * [mail merge query name$]" objword.mailmerge.execute objword.application.activedocument.saveas2 filename:="tmpmergeouput.docx" objword.application.activedocument.close objword.close savechanges:=wddonotsavechanges end sub notes:
- exporting xls worked - txt failed
- sqlstatement use [sheetname$] whe sheet name query name. see call mailmerge.opendatasource() set connection
- mail merge nested items (sub tables) https://support.microsoft.com/en-us/kb/294686
Comments
Post a Comment