I'm having difficutly in writing code that will mail merge a document with it's attached file. The attached file contains a field for the email address and one merge field with text that is passed to the document. The code listed below tries to merge the first record, email that document, close the active document and loop through the process until the last record has been processed. As you can see from the lines of code that have been rem'd out, I'm having a fun time at this.

Any advice would truly be appreciated.


The code is as follows:

Sub test()
Counter = 0
With Documents("HLBFS.Doc").MailMerge
.Destination = wdSendToNewDocument
' .Destination = wdSendToEmail
.MailAsAttachment = False
.MailAddressFieldName = "Email"
.MailSubject = "2002 Budget"
.SuppressBlankLines = True
' .DataSource.ActiveRecord =

LastPosition = .DataSource.ActiveRecord

Do Until Counter <= LastPosition
Counter = Counter + 1
With .DataSource
.FirstRecord = Counter
.LastRecord = LastPosition
End With

ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

End With
End Sub