5941 Error (1 Viewer)

Doga

New member
Local time
Today, 12:39
Joined
Apr 4, 2013
Messages
4
I am getting the below error when i am trying use the mail merge function in word application in word 2010

Run-time error '5941':
The requested member of the collection does not exist.


Code is as below line highlighted in bold is where error occurs:

Private Sub MergeMailDoc(as_Path As String, as_DocName As String, as_Where As String)
Dim ls_DbConnection As String
Dim ls_SqlStatement As String
Dim ls_DocPathName As String
Dim ls_DocName As String

Windows("ExamSpec.doc").Activate
Selection.EndKey Unit:=wdStory

ls_DocName = as_DocName
ls_DocPathName = as_Path & "\" & ls_DocName

If Len(Dir(ls_DocPathName)) = 0 Then
ls_DocName = "NoExamSpec.doc"
ls_DocPathName = as_Path & "\" & ls_DocName
End If

Application.Documents.Open ls_DocPathName

ls_DbConnection = as_Path & "\Prs_Data.mdb"

ls_SqlStatement = "SELECT * FROM `ExamSpecReport` " & as_Where

Documents("ExamSpec.doc").Application.Run "Mail_Merge", ls_DocName, ls_DbConnection, ls_SqlStatement

Documents("ExamSpec.doc").Application.Run "AppendMailMerge"

Documents(ls_DocName).Close False
End Sub
 

Rx_

Nothing In Moderation
Local time
Today, 01:09
Joined
Oct 22, 2009
Messages
2,803
Maybe this will help?

Are you using Option Explicit?
Sub OpenSales()
'Sales.doc must exist and be open but not active.
Documents("Sales.doc").Activate
End Sub
Sub automateword() ' just one of many ways to open a Word Doc
Set wordapp = CreateObject("word.Application")
wordapp.documents.Open "C:\Documents and Settings\NoExamSpec.doc"
' add your path information
wordapp.Visible = True
' then more automation
End Sub

A hint about bookmarks
MyWordObject = ActiveDocument.FormFields("bkDeptCode").Result
formfields and bookmarks: They are different. Formfields have bookmarks.
 

Users who are viewing this thread

Top Bottom