mailmerge to Word From Access

G

Guest

My Access app which ran FINE until yesterday is now throwing a "missing DLL"
error. The code that is now failinig is in a button that uses the common
dialog control and opens Word to complete mailmerge execution. It fails at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

In the area I cut out (for clairity). When I step-through the file name is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
 
G

Guest

A few other things: OS = XP Pro; running Office 2K, have no idea about
anything else as the system is part of a network. But prior to yesterday it
ran fine.
--
Loralee


Loralee said:
In the area I cut out (for clairity). When I step-through the file name is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


Douglas J. Steele said:
Where does strFilePath get set?
 
D

Douglas J. Steele

Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


Douglas J. Steele said:
Where does strFilePath get set?
 
G

Guest

Douglas,

May I inquiries as to why one should use the API instead of the common dialog?

Thank you,

Daniel




Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


Douglas J. Steele said:
Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a "missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
D

Douglas J. Steele

The major reason is that the common dialog is prone to versioning problems,
the API calls aren't.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Daniel said:
Douglas,

May I inquiries as to why one should use the API instead of the common
dialog?

Thank you,

Daniel




Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

I'll give that a try- but it doesn't appear that the call to the common
dialog that is causing the problem. In fact, the common dialog launches and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA Function
call?
--
Loralee


Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


Douglas J. Steele said:
Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a "missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

It's probably wise for me to find another way to talk to WORD from ACCESS,
(another was to Mail Merge or similiar) as undoubtedly there will be other
incompatabilities coming.
--
Loralee


Loralee said:
I'll give that a try- but it doesn't appear that the call to the common
dialog that is causing the problem. In fact, the common dialog launches and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA Function
call?
--
Loralee


Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID] =
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a "missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
D

Douglas J. Steele

Hold on. Since you've started another thread (seldom a good idea when you've
got an active one going), I would suspect that you're running into problems
with your References collection, since you've got users with different
versions of Word.

Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object

If you're using any intrinsic Word constants (they'll all start "wd"),
you'll need to get the values of those constants and define them in your
code once you've removed the reference.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I'll give that a try- but it doesn't appear that the call to the common
dialog that is causing the problem. In fact, the common dialog launches
and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA Function
call?
--
Loralee


Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

I apologize for the multiple threads! I'm new to this forum and used to one
that is fragmented.

So so I understand correctly that I can create an Object for Word, and
totally remove any reference to Word? Can I expect GetObject to work against
the dimmed Word.Object when it isn't currently working against the dimmed
Word.Document?
I am not referencing any other Word constants anywhere else. At the moment
both users have Word 2K. It is likely that my next project will include
users that have Work 2003, so I want to make this work in both arenas if
possible.

Thank you again,



--
Loralee


Douglas J. Steele said:
Hold on. Since you've started another thread (seldom a good idea when you've
got an active one going), I would suspect that you're running into problems
with your References collection, since you've got users with different
versions of Word.

Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object

If you're using any intrinsic Word constants (they'll all start "wd"),
you'll need to get the values of those constants and define them in your
code once you've removed the reference.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I'll give that a try- but it doesn't appear that the call to the common
dialog that is causing the problem. In fact, the common dialog launches
and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA Function
call?
--
Loralee


Douglas J. Steele said:
Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID], tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID] =
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses the
common
dialog control and opens Word to complete mailmerge execution. It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
D

Douglas J. Steele

I'm not sure why it's not working now, unless your References collection is
messed up.

Go into the VB Editor, and select Tools | References from the menu bar. Do
any of the selected references (i.e.: the ones at the top with check marks
beside them) have "MISSING: " in front of their name?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I apologize for the multiple threads! I'm new to this forum and used to
one
that is fragmented.

So so I understand correctly that I can create an Object for Word, and
totally remove any reference to Word? Can I expect GetObject to work
against
the dimmed Word.Object when it isn't currently working against the dimmed
Word.Document?
I am not referencing any other Word constants anywhere else. At the
moment
both users have Word 2K. It is likely that my next project will include
users that have Work 2003, so I want to make this work in both arenas if
possible.

Thank you again,



--
Loralee


Douglas J. Steele said:
Hold on. Since you've started another thread (seldom a good idea when
you've
got an active one going), I would suspect that you're running into
problems
with your References collection, since you've got users with different
versions of Word.

Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object

If you're using any intrinsic Word constants (they'll all start "wd"),
you'll need to get the values of those constants and define them in your
code once you've removed the reference.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I'll give that a try- but it doesn't appear that the call to the
common
dialog that is causing the problem. In fact, the common dialog
launches
and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA
Function
call?
--
Loralee


:

Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail
merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID],
tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID]
=
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON
tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses
the
common
dialog control and opens Word to complete mailmerge execution.
It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

Yeh, I did check that and nothing was missing. I even unchecked, then
rechecked Word and got the same result. I'll change the code to your
suggestion using Object tomorrow when I get into the office and see if that
makes any difference. I really want to get this back working as it saves me
and my co-worker alot of time. And I've been planning on using something
similliar in my current project.

Thanks
--
Loralee


Douglas J. Steele said:
I'm not sure why it's not working now, unless your References collection is
messed up.

Go into the VB Editor, and select Tools | References from the menu bar. Do
any of the selected references (i.e.: the ones at the top with check marks
beside them) have "MISSING: " in front of their name?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I apologize for the multiple threads! I'm new to this forum and used to
one
that is fragmented.

So so I understand correctly that I can create an Object for Word, and
totally remove any reference to Word? Can I expect GetObject to work
against
the dimmed Word.Object when it isn't currently working against the dimmed
Word.Document?
I am not referencing any other Word constants anywhere else. At the
moment
both users have Word 2K. It is likely that my next project will include
users that have Work 2003, so I want to make this work in both arenas if
possible.

Thank you again,



--
Loralee


Douglas J. Steele said:
Hold on. Since you've started another thread (seldom a good idea when
you've
got an active one going), I would suspect that you're running into
problems
with your References collection, since you've got users with different
versions of Word.

Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object

If you're using any intrinsic Word constants (they'll all start "wd"),
you'll need to get the values of those constants and define them in your
code once you've removed the reference.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I'll give that a try- but it doesn't appear that the call to the
common
dialog that is causing the problem. In fact, the common dialog
launches
and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA
Function
call?
--
Loralee


:

Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail
merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID],
tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID]
=
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON
tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses
the
common
dialog control and opens Word to complete mailmerge execution.
It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 
G

Guest

Well, your suggestion to
"Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object ", along with removing the reference to Word worked.
So we're back running. I plan to follow up on changing the Common Dialog
Call to an API call (I haven't done an API call yet!) and probably implement
Allen Kallel's suggestion in my current project.

Again, thanks! I appreciate everyone's help.

--
Loralee


Loralee said:
Yeh, I did check that and nothing was missing. I even unchecked, then
rechecked Word and got the same result. I'll change the code to your
suggestion using Object tomorrow when I get into the office and see if that
makes any difference. I really want to get this back working as it saves me
and my co-worker alot of time. And I've been planning on using something
similliar in my current project.

Thanks
--
Loralee


Douglas J. Steele said:
I'm not sure why it's not working now, unless your References collection is
messed up.

Go into the VB Editor, and select Tools | References from the menu bar. Do
any of the selected references (i.e.: the ones at the top with check marks
beside them) have "MISSING: " in front of their name?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Loralee said:
I apologize for the multiple threads! I'm new to this forum and used to
one
that is fragmented.

So so I understand correctly that I can create an Object for Word, and
totally remove any reference to Word? Can I expect GetObject to work
against
the dimmed Word.Object when it isn't currently working against the dimmed
Word.Document?
I am not referencing any other Word constants anywhere else. At the
moment
both users have Word 2K. It is likely that my next project will include
users that have Work 2003, so I want to make this work in both arenas if
possible.

Thank you again,



--
Loralee


:

Hold on. Since you've started another thread (seldom a good idea when
you've
got an active one going), I would suspect that you're running into
problems
with your References collection, since you've got users with different
versions of Word.

Try removing the reference you have to Word, and changing

Dim objWord As Word.Document

to

Dim objWord As Object

If you're using any intrinsic Word constants (they'll all start "wd"),
you'll need to get the values of those constants and define them in your
code once you've removed the reference.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I'll give that a try- but it doesn't appear that the call to the
common
dialog that is causing the problem. In fact, the common dialog
launches
and
takes user's selection as strFilePath.

It is the line GetObject that is highlighted. Is that not a VBA
Function
call?
--
Loralee


:

Scrap the Common Dialog. Use the API approach demonstrated in
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

Far more reliable...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


In the area I cut out (for clairity). When I step-through the file
name
is
passing fine. The WHOLE sub is:


Private Sub cmdMergeLetter_Click()
' this is an attempt to open a Word document and start a mail
merge
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

strPatientID = Forms!frmpatientdata.txtPatientID
strSELECT = "SELECT tblPatient.[PatientID],
tblPatient.[PtFirstName],
tblPatient.[PtLastName], tblPatient.[PtBD], tblCity.[City],
tblPatient.[PtAddress], tblPatient.[PtZip], tblReferral.[ReferBy]"
strFROM = " FROM (tblCity INNER JOIN tblPatient ON tblCity.[CityID]
=
tblPatient.[PtCityFK]) INNER JOIN tblReferral ON
tblPatient.[PatientID]
=
tblReferral.[PtFK]"
strWHERE = " WHERE ((([PatientID])= " & strPatientID & "))"
strSQLMerge = strSELECT & strFROM & strWHERE

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Me.cmdlg.DialogTitle = "Choose File Name and Location"
Me.cmdlg.ShowOpen
strFilePath = Me.cmdlg.FileName

Set objWord = GetObject(strFilePath, "Word.document")

' make word visible
objWord.Application.Visible = True



' execute the mail merge
objWord.MailMerge.Execute
objWord.Close



--
Loralee


:

Where does strFilePath get set?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


My Access app which ran FINE until yesterday is now throwing a
"missing
DLL"
error. The code that is now failinig is in a button that uses
the
common
dialog control and opens Word to complete mailmerge execution.
It
fails
at
getobject().

See below.
1) Does anyone know of another way to get to Word from Access?
2) Has this recently happened to anyone else?

====================
Dim strFilePath As String
Dim objWord As Word.Document
Dim strPatientID As String ' use to link to patient
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
Dim strSQLMerge As String

'i removed the SQL concantenation code as error not there

CurrentDb.QueryDefs("qrymailmerge").SQL = strSQLMerge

Set objWord = GetObject(strFilePath, "Word.document") 'fails here
' make word visible
objWord.Application.Visible = True

' execute the mail merge
objWord.MailMerge.Execute
objWord.Close
Thanks!
 

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