VBA Mail Merge (1 Viewer)

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
Hi All

I want a click button that will start a mail merge in Access, so far I've tinkered around with some code over the past week and when running the below code which just opens the Word doc but does nothing else.

Any help would be lovely :D

Dim MailMergeFile As String
Dim objWord As Word.Document
Dim i As Integer

Set objWord = GetObject("C:\Users\CustomerDB\Desktop\mymerge.docx", "Word.Document")

objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
Name:="C:\Users\User\Desktop\CustomerDB.accdb", _
LinkToSource:=True, _
Connection:="TABLE TblCustomerDetails", _
SQLStatement:="SELECT * FROM [TblCustomerDetails]"

objWord.MailMerge.Execute


For i = 1 To objWord.Application.Documents.Count - 1
objWord.Application.Documents(i).Close wdSaveNo
Next i
:banghead::banghead::banghead:
 
Last edited:

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
Thanks for getting back to me, looks very intersting. :D
 

RuralGuy

AWF VIP
Local time
Today, 09:22
Joined
Jul 2, 2005
Messages
13,826
It is just one line of code in your current project and it works great.
 

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
Not sure i understand what you mean?

The code above just opens Word but doesn't start a mail merge.

And the same with the link you gave me, I down loaded the DB and it just opens Word and not mail merge.
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 08:22
Joined
Nov 8, 2005
Messages
3,294
read the instructions - you have to add the fields in as normal
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 08:22
Joined
Nov 8, 2005
Messages
3,294
are you wanting a mail merge of x records or individual record

super easy word merge is ideal for 1 record merging into word
create the template and then push the button works a treat
ensure you d/b is split
 

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
I'd like the option to mail merge one or lots of records.
 

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
Also I've followed theeasy word merge and I just get compile errors throughout the code. :banghead::banghead:
 

RuralGuy

AWF VIP
Local time
Today, 09:22
Joined
Jul 2, 2005
Messages
13,826
Did you import the two modules and the two forms into your db?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:22
Joined
Sep 12, 2006
Messages
15,658
this any use?

Code:
    Set objWordDoc = objWord.documents.Open(MergeDocument)
 
    objWordDoc.MailMerge.OpenDataSource _
        [COLOR=red]Name:=MergeData[/COLOR], ConfirmConversions:=False, _
        ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
        WritePasswordTemplate:="", Revert:=False, Format:=0, _
        Connection:="", SQLStatement:="", SQLStatement1:=""
     objWordDoc.MailMerge.Destination = 0 'wdSendToNewDocument
    
    objWordDoc.MailMerge.Execute
in this case the mergedata is a csv
maybe the way you are specifying your record source is not correct.
 

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
Hi guys

Thanks for all your help! it looks like I may have cracked it with easy mail merge. Will keep you posted if any different.
 

Neilster

Registered User.
Local time
Today, 08:22
Joined
Jan 19, 2014
Messages
218
My only issue with Super Easy Word Merge by Albert D. Kallal is that when you filter your databasefor certain criteria like say a specific city and then you do the mail merge it still merges the entire database????
 

RuralGuy

AWF VIP
Local time
Today, 09:22
Joined
Jul 2, 2005
Messages
13,826
How are you invoking the WordMerge. You hand it an SQL statement, right?
 

RuralGuy

AWF VIP
Local time
Today, 09:22
Joined
Jul 2, 2005
Messages
13,826
Does that SQL have a where clause or some sort of limiting clause in it?
 

RuralGuy

AWF VIP
Local time
Today, 09:22
Joined
Jul 2, 2005
Messages
13,826
Sorry about the delay but site did not tell me of your post. Where is your line of code that invokes the MailMerge? Please post it for me to see.
 

Users who are viewing this thread

Top Bottom