Hello sir,
I am using mailmerge by vba with following code:
Code:
Private Sub MailMerge_Click()On Error GoTo DoMailMerge_Err
'Nodte: A VBA Reference to the Word Object Model is required, via Tools|References
Dim wdApp As New word.Application, wdDoc As word.Document
Dim strWorkbookName As String: strWorkbookName = CurrentProject.FullName
With wdApp
'Disable alerts to prevent an SQL prompt
.DisplayAlerts = wdAlertsNone
'Open the mailmerge main document
Set wdDoc = .Documents.Open(CurrentProject.Path & "\" & [GteeIssueADSubForm].Form![GTEE_FORMATE], _
ConfirmConversions:=False, ReadOnly:=True, AddToRecentfiles:=False)
With wdDoc
With .MailMerge
'Define the mailmerge type
.MainDocumentType = wdFormLetters
'Define the output
.Destination = wdSendToNewDocument
.SuppressBlankLines = False
'Connect to the data source
.OpenDataSource Name:=strWorkbookName, ReadOnly:=False, _
LinkToSource:=True, AddToRecentfiles:=False, _
Format:=wdOpenFormatAuto, _
Connection:="TABLE GteeTrayTbl", _
SQLStatement:="SELECT * FROM [GteeTrayTbl]", _
SubType:=wdMergeSubTypeAccess
With .DataSource
.FirstRecord = InputBox("Enter the First Record # to merge", , 1)
.LastRecord = InputBox("Enter the Last Record # to merge", , .RecordCount) ' replace 2o to .RecordCount to get record count
End With
'Excecute the merge
.Execute
'Disconnect from the data source
.MainDocumentType = wdNotAMergeDocument
End With
'Close the mailmerge main document
.Close False
End With
'Restore the Word alerts
.DisplayAlerts = wdAlertsAll
'Display Word and the document
.Visible = True
End With
DoMailMerge_Exit:
Exit Sub
DoMailMerge_Err:
Select Case MsgBox(Error$)
End Select
Resume DoMailMerge_Exit
End Sub
It works properly.
I want to update my "Remarks" field with value "Done" which data I have successfully mailmerged with same click(I mean to say with same command button).
i.e.
With .DataSource .FirstRecord = InputBox("Enter the First Record # to merge", , 1)
.LastRecord = InputBox("Enter the Last Record # to merge", , .RecordCount) ' replace 2o to .RecordCount to get record count
End With
this recordset fields' "remarks" should be updated as "Done".
I'm using Access2007, window 10.
Thanks in advance.