A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Mail Merge Functionality



 
 
Thread Tools Display Modes
  #1  
Old May 22nd 13, 07:28 AM
Doga Doga is offline
Junior Member
 
First recorded activity by WordBanter: May 2013
Posts: 1
Red face Mail Merge Functionality

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

Method 'Run' of Object '_Application' Fail amd it is asking for the 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 provided 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 * FROM `ExamSpecReport` WHERE...
'
' RETURN: None
'
' COMMENTS:
'
' WRITTEN BY: (Advantica) DATE: -
' ================================================== =============================================
' HISTORY:
' Initials Date Comment
' Claud G 06/12/05 Added Subtype:=wdMergeSubTypeWord2000. This suppresses the datalink
' properties dialogue from continually appearing 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=MS Access;MaxBufferSize=2048;PageTimeout=5;", _
SQLStatement:=as_SqlStatement, _
SQLStatement1:="", _
Subtype:=wdMergeSubTypeWord2000 ' Makes sure the mailmerge 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 Sub
Ads
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail-Merge: Can we have master detail relationship or multiple entities in word Mail-Merge? gmax2006 Microsoft Word Help 1 March 28th 07 06:28 PM
Take Mail Merge in Word back the the Mail Merge Helper 1,2,3 Form. Chris Green Mailmerge 5 October 8th 05 03:51 PM
Mail merge has lost significant functionality in Word 2003 bdq Mailmerge 1 March 22nd 05 10:01 PM
Proteced Form with Mail Merge Section-Mail Merge is "lost" whe F. Ferrer Microsoft Word Help 0 February 2nd 05 09:27 PM
mail merge doc with further linked/embedded mail merge docs not playing the game Rob Cowlard Mailmerge 3 January 8th 05 10:15 AM


All times are GMT +1. The time now is 09:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright 2004-2020 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.