A
akidner
While trying to perform a Word mail merge from vb code in an Access form I am
getting the following: “Run-time error 5852†~ “Requested object is not
availableâ€. I have used very similar code without a problem from Access 2000
but I am now using the 2003 version. I have Word 11.0 Object Library in the
references.
I am adding some code below but I wonder if the problem lies elsewhere.
Updates happen automatically on our network and recently I have started to
get an Unknown Publisher security warning notice when I double click the
database icon to open it. I am also now getting a warning when I manually
open the Word document; it says “Opening this document will run the following
SQL command . . .â€
My code successfully opens Word and the correct document but when I
investigate it after the error, I find that Word does not seem to have the
data source available even though it works okay if I open the doc manually
(having said yes to the SQL warning).
Any help would be most welcome. Sample of code follows:
Option Compare Database
Option Explicit
Private Sub cmdPrint_Click()
Dim strDocName As String
Dim strAlert As String
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim rstPrintDone As DAO.Recordset
Dim A As Long
Let strDocName = txtID.Value & "_" & Date
..
..
'Error message at the next line
appWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument '= 0
'= the value of Const wdSendToNewDocument. N.B. Can not send to print here
without dialog box requiring an OK button click
appWord.ActiveDocument.MailMerge.Execute 'Send the data to the new
document now
appWord.ActiveDocument.PrintOut Background:=False 'New doc is now
active. We print it without a dialog box
appWord.ActiveDocument.Close wdDoNotSaveChanges 'We close the new doc
docWord.Close wdDoNotSaveChanges 'We close our original document.
..
..
AbortPrint:
appWord.Quit
Set docWord = Nothing
Set appWord = Nothing
Set rstPrintDone = Nothing
End Sub
getting the following: “Run-time error 5852†~ “Requested object is not
availableâ€. I have used very similar code without a problem from Access 2000
but I am now using the 2003 version. I have Word 11.0 Object Library in the
references.
I am adding some code below but I wonder if the problem lies elsewhere.
Updates happen automatically on our network and recently I have started to
get an Unknown Publisher security warning notice when I double click the
database icon to open it. I am also now getting a warning when I manually
open the Word document; it says “Opening this document will run the following
SQL command . . .â€
My code successfully opens Word and the correct document but when I
investigate it after the error, I find that Word does not seem to have the
data source available even though it works okay if I open the doc manually
(having said yes to the SQL warning).
Any help would be most welcome. Sample of code follows:
Option Compare Database
Option Explicit
Private Sub cmdPrint_Click()
Dim strDocName As String
Dim strAlert As String
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim rstPrintDone As DAO.Recordset
Dim A As Long
Let strDocName = txtID.Value & "_" & Date
..
..
'Error message at the next line
appWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument '= 0
'= the value of Const wdSendToNewDocument. N.B. Can not send to print here
without dialog box requiring an OK button click
appWord.ActiveDocument.MailMerge.Execute 'Send the data to the new
document now
appWord.ActiveDocument.PrintOut Background:=False 'New doc is now
active. We print it without a dialog box
appWord.ActiveDocument.Close wdDoNotSaveChanges 'We close the new doc
docWord.Close wdDoNotSaveChanges 'We close our original document.
..
..
AbortPrint:
appWord.Quit
Set docWord = Nothing
Set appWord = Nothing
Set rstPrintDone = Nothing
End Sub