Run time error '287'

E

Emma Aumack

Hi all,

Here I am again, still working on getting the automation to work with Access
and Word mail merge. I am no longer getting the Word cannot open the data
source error but now I am getting the above referenced "Run-time error '287':
Application-defined or object-defined error" which really stumps me because
I got the code from article #209976. See below:

Function MergeItExp()
Dim ObjWord As Word.Document
Set ObjWord =
GetObject("G:\User\Contracts\Data_Files\Access_Security\Expire_Letters.doc",
"Word.Document")

' Make Word Visible
ObjWord.Application.Visible = True

' Set the mail merge data source as the Contracts_Database.mdb
ObjWord.MailMerge.OpenDataSource
Name:="G:\User\Contracts\Data_Files\Access_Security\copy (3) of
contracts_database.mdb", _
LinkToSource:=True, _
PasswordDocument:="", _
Connection:="QUERY Qry_Letters_BPV_CmplExpired", _
SQLStatement:="SELECT * FROM Qry_Letters_BPV_CmplExpired"

' Execute the mailmerge

ObjWord.MailMerge.Execute


End Function

I think it might have to do with my references but I can't seem to put my
finger on it. I researched and worked on this all day. Can someone please
help me?

Thank you,
 
V

Van T. Dinh

Not sure but try the following:

1. Remove the PasswordDocument from the OpenDataSource statement
or
2. Enclose your Query name in square brackets (2 occurences)
or
3. Both 1 & 2.

Can you identify which line of code errored out?

AFAICS, you need the Word Object Library but it must have already been
included in the References since otherwise, you get compilation error on the
Dim statement.

I assumed that the doc "Expire_Letters.doc" has been designed as a MailMerge
doc...
 
6

'69 Camaro

Hi, Emma.
I am no longer getting the Word cannot open the data
source error but now I am getting the above referenced "Run-time error
'287':
Application-defined or object-defined error"

When using GetObject( ), make sure the application is already open,
otherwise you'll get an error. If you can't be sure it's already open when
your code runs, use CreateObject( ). For example:

Dim appWord As Object
Dim ObjWord As Object

Set appWord = CreateObject("Word.Application")
appWord.Visible = True
Set ObjWord =
appWord.Documents.Open("G:\User\Contracts\Data_Files\Access_Security\Expire_Letters.doc")
' Rest of code follows.

With this syntax, you don't need to set a reference to Word.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
V

Van T. Dinh

Did you open the Word application + the doc previously by code or through
the normal GUI?

If you haven't, I am fairly sure you need to use CreateObject instead ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top