UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Exporting To Word Possible Mail Merge, Access 2016    
 
   
dashiellx2000
post May 27 2019, 02:00 PM
Post#1


UtterAccess VIP
Posts: 9,829
Joined: 11-March 05
From: Maryland


OK. in the past I've never needed to do a mail merge as all my Word automation was exceedingly simple so there was never a need to go past the bookmark method.

However, a friend of my is in need of an estimate form for his roofing company. I told him I wasn't sure if the way I know would be the best and would happily refer him to someone. He said no, that it is really more a gravy item for him and that he thought i could lean something new and in return he'd help me reno my kitchen. Can't really pass that offer up.

So....I made the attached word template and have read everything at Kallal Super Easy Word Merge.

I have not been able to test Kallal's solution as I get an error on it:
QUOTE
"Compile error: The code in this project must be updated for use on 64-bit systems" error message when you edit a VBA macro in the 64-bit version of an Office 2010 program


Other mail merge examples I've found don't make much sense, there is very little code and I can't follow how it works. With bookmarks, it made sense: you set each bookmark the the value you want. But I'm not seeing that with mail merging.

also, in the middle of the letter, there is a section that is for detailing the estimate line items. I was thinking of putting this info in a table there, more for alignment purposes, but haven't been successful in getting a table to actually work.

Any help would be greatly appreciated.

Thanks.

William.
Attached File(s)
Attached File  EstimateTemplateExample.zip ( 18.16K )Number of downloads: 4
 

--------------------
William
“We're run by the Pentagon, we're run by Madison Avenue, we're run by television, and as long as we accept those things and don't revolt we'll have to go along with the stream to the eventual avalanche"
Go to the top of the page
 
theDBguy
post May 27 2019, 03:46 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,316
Joined: 19-June 07
From: SunnySandyEggo


Hi William. If you're getting a compile error, you must be using a 64-bit Access. If so, you'll need to adjust all API declarations to work with 64-bit.

Edit: Also, does the template you posted not have any data source?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
gemmathehusky
post May 27 2019, 04:34 PM
Post#3


UtterAccess VIP
Posts: 4,725
Joined: 5-June 07
From: UK


mailmerge. I hope this helps.

I can't comment on bitness errors. As this is just using office directly, it might work - but you never know.


briefly, I have a word doc, prepared against a csv file. The word doc has merge codes at various places, to collect values from each row of the csv file. (so 1 per estimate in your case)

In access I generate a new csv file with a query, and then open the word merge master document, passing it the path of the csv file, and the path of the new merged output document. This example is using late binding.


This code to call the mail merge

CODE
    If Not DoMailmerge(wordtemplateFile, csvdataFile, outFile) Then   'all strings
        'report error
    end if


;this code to perfrom the mailmerge

CODE
Public Function DoMailmerge(MergeDocument As String, MergeData As String, OutputDocument As String) As Boolean
'On Error GoTo DoMailmerge_Error  'not included here
    
    Dim objWord As Object
    Dim objWordDoc As Object
    Dim strMailmergeDataFilename As String
    
    Set objWord = CreateObject("Word.Application") ' new copy of word
    objWord.Application.Visible = True
    objWord.DisplayAlerts = False
    
    'open the template
    Set objWordDoc = objWord.documents.Open(MergeDocument)

    'FormatCode: bound word constant is = wdOpenFormatAuto

    objWordDoc.MailMerge.OpenDataSource _
        Name:=MergeData, ConfirmConversions:=False, _
        ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
        WritePasswordTemplate:="", Revert:=False, Format:=0, _
        Connection:="", SQLStatement:="", SQLStatement1:=""

    objWordDoc.MailMerge.Destination = 0 'bound wordconstant is wdSendToNewDocument
    
    objWordDoc.MailMerge.Execute
    
    DoMailmerge = True


;error handler section returns false if there is an error


end function

--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th September 2019 - 03:24 PM