Word/Access mail merge automation help needed 
Author Message
 Word/Access mail merge automation help needed

I recorded a macro for mail merge in Word, then cut and pasted it into
Access.  I
incorporated some code from the A97 Developers manual, but I'm missing
something.
I'm getting a Type Mismatch (Error13).  When I debug, it's halting at
"Set objWd =
GetObject("K:\Philips Lighting\Letters\Solicitation Form Letter.dot")".
Hopefully someone can help me understand what the very long help file is

trying to say in english.

Also, when the word file opens and goes through
"MailMerge.OpenDataSource", it is opening another version of the Access
database that triggered Word in the first place.  What must I change to
get it to read the query from the database that's already open?  The
code I have so far is below.  THANKS ALL, for your help.

Option Compare Database
Option Explicit
Dim objWd As Document
Function Merge()
' setandmerge Macro
' Macro recorded 04/16/01 by Renee Moffett
Set objWd = GetObject("K:\Client\Letters\Solicitation Form
Letter.dot")
    ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
    ActiveDocument.MailMerge.OpenDataSource Name:= _
        "\\LOU1\Kommon\Client\Philips 1.0.mdb",
ConfirmConversions:= _
        False, ReadOnly:=False, LinkToSource:=True,
AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
        WritePasswordTemplate:="", Revert:=False,
Format:=wdOpenFormatAuto, _
        Connection:="QUERY qrySolicitation", SQLStatement:= _
        "SELECT * FROM [qrySolicitation]", SQLStatement1:=""
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .MailAsAttachment = False
        .MailAddressFieldName = ""
        .MailSubject = ""
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=True
    End With

End Function



Sat, 04 Oct 2003 02:53:37 GMT  
 Word/Access mail merge automation help needed
Hi Renee,

Well you can't cut-copy-paste directlly from a word macro into Access, some
stuff do need some changes, the basic is there, but there are things that
are diferent.

Try looking at the folowing KB Article
http://support.microsoft.com/support/kb/articles/q159/3/28.asp

hope this can lead the way...


Quote:
>I recorded a macro for mail merge in Word, then cut and pasted it into
>Access.  I
>incorporated some code from the A97 Developers manual, but I'm missing
>something.
>I'm getting a Type Mismatch (Error13).  When I debug, it's halting at
>"Set objWd =
>GetObject("K:\Philips Lighting\Letters\Solicitation Form Letter.dot")".
>Hopefully someone can help me understand what the very long help file is

>trying to say in english.

>Also, when the word file opens and goes through
>"MailMerge.OpenDataSource", it is opening another version of the Access
>database that triggered Word in the first place.  What must I change to
>get it to read the query from the database that's already open?  The
>code I have so far is below.  THANKS ALL, for your help.

>Option Compare Database
>Option Explicit
>Dim objWd As Document
>Function Merge()
>' setandmerge Macro
>' Macro recorded 04/16/01 by Renee Moffett
>Set objWd = GetObject("K:\Client\Letters\Solicitation Form
>Letter.dot")
>    ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
>    ActiveDocument.MailMerge.OpenDataSource Name:= _
>        "\\LOU1\Kommon\Client\Philips 1.0.mdb",
>ConfirmConversions:= _
>        False, ReadOnly:=False, LinkToSource:=True,
>AddToRecentFiles:=False, _
>        PasswordDocument:="", PasswordTemplate:="",
>WritePasswordDocument:="", _
>        WritePasswordTemplate:="", Revert:=False,
>Format:=wdOpenFormatAuto, _
>        Connection:="QUERY qrySolicitation", SQLStatement:= _
>        "SELECT * FROM [qrySolicitation]", SQLStatement1:=""
>    With ActiveDocument.MailMerge
>        .Destination = wdSendToNewDocument
>        .MailAsAttachment = False
>        .MailAddressFieldName = ""
>        .MailSubject = ""
>        .SuppressBlankLines = True
>        With .DataSource
>            .FirstRecord = wdDefaultFirstRecord
>            .LastRecord = wdDefaultLastRecord
>        End With
>        .Execute Pause:=True
>    End With

>End Function

-----------------------------------
Pedro Gil
http://www.geocities.com/pmpg98_pt/


Sat, 04 Oct 2003 08:04:45 GMT  
 Word/Access mail merge automation help needed
Renee,

If you're trying to open a Word document from another application, you have
to first create an instance of Word:
    Dim wrd As Word.Application
    Set wrd = GetObject(, "Word.Application")

Then you can open the document:
    wrd.Documents.Open strDocName, , booReadOnly, strPassword,
strTemplatePassword
or template:
    wrd.Documents.Add Template:=strTemplateName

To close the document, use:
    wrd.ActiveDocument.Close savechanges:=wdPromptToSaveChanges

Then to close Word:
    wrd.Application.Quit savechanges:=wdPromptToSaveChanges
    Set wrd = Nothing

------
Graham R Seach MCP Microsoft Access
Pacific Database (Australia) Pty Limited

------


Quote:
> I recorded a macro for mail merge in Word, then cut and pasted it into
> Access.  I
> incorporated some code from the A97 Developers manual, but I'm missing
> something.
> I'm getting a Type Mismatch (Error13).  When I debug, it's halting at
> "Set objWd =
> GetObject("K:\Philips Lighting\Letters\Solicitation Form Letter.dot")".
> Hopefully someone can help me understand what the very long help file is

> trying to say in english.

> Also, when the word file opens and goes through
> "MailMerge.OpenDataSource", it is opening another version of the Access
> database that triggered Word in the first place.  What must I change to
> get it to read the query from the database that's already open?  The
> code I have so far is below.  THANKS ALL, for your help.

> Option Compare Database
> Option Explicit
> Dim objWd As Document
> Function Merge()
> ' setandmerge Macro
> ' Macro recorded 04/16/01 by Renee Moffett
> Set objWd = GetObject("K:\Client\Letters\Solicitation Form
> Letter.dot")
>     ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
>     ActiveDocument.MailMerge.OpenDataSource Name:= _
>         "\\LOU1\Kommon\Client\Philips 1.0.mdb",
> ConfirmConversions:= _
>         False, ReadOnly:=False, LinkToSource:=True,
> AddToRecentFiles:=False, _
>         PasswordDocument:="", PasswordTemplate:="",
> WritePasswordDocument:="", _
>         WritePasswordTemplate:="", Revert:=False,
> Format:=wdOpenFormatAuto, _
>         Connection:="QUERY qrySolicitation", SQLStatement:= _
>         "SELECT * FROM [qrySolicitation]", SQLStatement1:=""
>     With ActiveDocument.MailMerge
>         .Destination = wdSendToNewDocument
>         .MailAsAttachment = False
>         .MailAddressFieldName = ""
>         .MailSubject = ""
>         .SuppressBlankLines = True
>         With .DataSource
>             .FirstRecord = wdDefaultFirstRecord
>             .LastRecord = wdDefaultLastRecord
>         End With
>         .Execute Pause:=True
>     End With

> End Function



Sat, 04 Oct 2003 12:55:53 GMT  
 Word/Access mail merge automation help needed
Renee,

There is another news group called microsoft.public.office.developer.automation
(you might try there)

I always export to 'mail merge' or excel, and then merge from word or excel
(I normally have fairly short mailing lists).  My clients can look at the data in
excel and then do a normal Word mail merge if they don't like the automatic
result.  And the great thing about a mail merge from a word table to a word
document is that it does not start access to get the data....

Quote:

> I recorded a macro for mail merge in Word, then cut and pasted it into
> Access.  I
> incorporated some code from the A97 Developers manual, but I'm missing
> something.
> I'm getting a Type Mismatch (Error13).  When I debug, it's halting at
> "Set objWd =
> GetObject("K:\Philips Lighting\Letters\Solicitation Form Letter.dot")".
> Hopefully someone can help me understand what the very long help file is

> trying to say in english.

> Also, when the word file opens and goes through
> "MailMerge.OpenDataSource", it is opening another version of the Access
> database that triggered Word in the first place.  What must I change to
> get it to read the query from the database that's already open?  The
> code I have so far is below.  THANKS ALL, for your help.

> Option Compare Database
> Option Explicit
> Dim objWd As Document
> Function Merge()
> ' setandmerge Macro
> ' Macro recorded 04/16/01 by Renee Moffett
> Set objWd = GetObject("K:\Client\Letters\Solicitation Form
> Letter.dot")
>     ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
>     ActiveDocument.MailMerge.OpenDataSource Name:= _
>         "\\LOU1\Kommon\Client\Philips 1.0.mdb",
> ConfirmConversions:= _
>         False, ReadOnly:=False, LinkToSource:=True,
> AddToRecentFiles:=False, _
>         PasswordDocument:="", PasswordTemplate:="",
> WritePasswordDocument:="", _
>         WritePasswordTemplate:="", Revert:=False,
> Format:=wdOpenFormatAuto, _
>         Connection:="QUERY qrySolicitation", SQLStatement:= _
>         "SELECT * FROM [qrySolicitation]", SQLStatement1:=""
>     With ActiveDocument.MailMerge
>         .Destination = wdSendToNewDocument
>         .MailAsAttachment = False
>         .MailAddressFieldName = ""
>         .MailSubject = ""
>         .SuppressBlankLines = True
>         With .DataSource
>             .FirstRecord = wdDefaultFirstRecord
>             .LastRecord = wdDefaultLastRecord
>         End With
>         .Execute Pause:=True
>     End With

> End Function



Sun, 05 Oct 2003 15:30:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. NEED HELP, Coding Access to Word Mail Merge :-)

2. Access 97 to Word Mail Merge Automation

3. newbie needs code help for word mail merge

4. Word Mail Merge Err - Word could not merge...

5. Automation of Mail Merge in Word

6. Help with Mail Merge from Access to Word

7. Help needed automating mail merge in access and MSword

8. Access to Word Merge Automation

9. Mail Merge automation help

10. Formatting Merge Fields in Word Mail Merge

11. Word Newbie needs to do a complex mail merge

12. Access/Word mail merge

 

 
Powered by phpBB® Forum Software