Mail Merge Functionality

D

Doga

I am getting below error when i click on the Mail Merge button in cod
--

Method 'Run' of Object '_Application' Fail amd it is asking for th
password code is as below

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
Documents("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

****************************************************
Private Sub Mail_Merge( _
as_DocName As String, _
as_DbConnection As String, _
as_SqlStatement As String)


===============================================================================================
' PURPOSE: Implement the built in mail merge functionality provide
by MS Word
'
' INVOCATION: Macro within this document
'
' ASSUMPTIONS: None
'
' EFFECTS: tblJobs
'
' INPUTS: as_DocName - Output document name
' as_DbConnection - Full data source path name
' as_SqlStatement - Data source E.g "SELECT * FRO
`ExamSpecReport` WHERE...
'
' RETURN: None
'
' COMMENTS:
'
' WRITTEN BY: (Advantica) DATE: -

===============================================================================================
' HISTORY:
' Initials Date Comment
' Claud G 06/12/05 Added Subtype:=wdMergeSubTypeWord2000. Thi
suppresses the datalink
' properties dialogue from continually appearin
when word connects to the
' MS Access data source.

===============================================================================================

With Documents(as_DocName).MailMerge

.OpenDataSource _
Name:=as_DbConnection, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="DSN=MS Access Database;DBQ=" & as_DbConnection
";PWD=" & ms_DbPassword & ";DriverId=25;FIL=M
Access;MaxBufferSize=2048;PageTimeout=5;", _
SQLStatement:=as_SqlStatement, _
SQLStatement1:="", _
Subtype:=wdMergeSubTypeWord2000 ' Makes sure the mailmerg
behaves as in Word2K

.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With
End Su
 

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