Mail Merge Macro

Z

ZZK

I need help debugging the following code. I'm a novice, so please don't
laugh at me. :) When I run it, it only merges the very first record in the
data source. Basically, all I want it to do is select a record from the data
source, based on an account number and merge that particular record. What's
missing? Any help would be greatly appreciated!


Sub SRFulfill()
'
' SRFulfill Macro
'
Dim strEnterAcct As String
Dim dsMain As MailMergeDataSource
Dim intRecordNum As Integer


strEnterAcct = InputBox("Please Enter an Account Number", "Enter Account")

Set dsMain = ActiveDocument.MailMerge.DataSource

If dsMain.FindRecord(FindText:=strEnterAcct, Field:="ACCOUNT") = True Then
intRecordNum = dsMain.ActiveRecord
End If

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = intRecordNum
.LastRecord = intRecordNum
End With
.Execute Pause:=False
End With

End Sub
 
C

Cindy Meister

Which version of Word is this running in?

If you comment out the code after performing FindRecord, is that record
visible on the screen (has it become the ActiveRecord)? Or are you still
looking at the first record?

FWIW, FindRecord has been faulty since Word 2000. There were ways of working
around this, but the problem changed in Word 2002, making the situation even
worse.

Personally, I think it's better to set the mailmerge.datasource.Querystring
property so that the mail merge contains only the record(s) that meet the
search criteria.

-- Cindy
 

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