From: Emma Aumack on
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,
--
www.bardpv.com
Tempe, Arizona
From: Van T. Dinh on
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...

--
HTH
Van T. Dinh
MVP (Access)



"Emma Aumack" <emma.aumack(a)crbard.com> wrote in message
news:2D90383E-35E4-47CB-9DC6-16DC473D5AF3(a)microsoft.com...
> 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,
> --
> www.bardpv.com
> Tempe, Arizona


From: Emma Aumack on
thanks for your reply but neither of these fixed the problem. The debugger
is highlighting

Set ObjWord = GetObject ("G:\User\Contracts\....

which makes me think that I am missing a library. Any other suggestions?
--
www.bardpv.com
Tempe, Arizona


"Van T. Dinh" wrote:

> 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...
>
> --
> HTH
> Van T. Dinh
> MVP (Access)
>
>
>
> "Emma Aumack" <emma.aumack(a)crbard.com> wrote in message
> news:2D90383E-35E4-47CB-9DC6-16DC473D5AF3(a)microsoft.com...
> > 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,
> > --
> > www.bardpv.com
> > Tempe, Arizona
>
>
>
From: '69 Camaro on
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.


"Emma Aumack" <emma.aumack(a)crbard.com> wrote in message
news:2D90383E-35E4-47CB-9DC6-16DC473D5AF3(a)microsoft.com...
> 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,
> --
> www.bardpv.com
> Tempe, Arizona


From: Van T. Dinh on
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 ...

--
HTH
Van T. Dinh
MVP (Access)




"Emma Aumack" <emma.aumack(a)crbard.com> wrote in message
news:CDECF6D8-6492-4D5F-9A2B-E0EE621382BB(a)microsoft.com...
> thanks for your reply but neither of these fixed the problem. The
> debugger
> is highlighting
>
> Set ObjWord = GetObject ("G:\User\Contracts\....
>
> which makes me think that I am missing a library. Any other suggestions?
> --
> www.bardpv.com
> Tempe, Arizona
>
>


 | 
Pages: 1
Prev: Really Appreciate Help
Next: Error on Close?