Reading the values of a datasource
Posted on 2004-09-14
I am trying to do this prog that can activate mail merge on a doc with it's datasource defined. During the merge, I will send the doc into a virtual printer to convert it into pdf.
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open("C:\Test4.doc", , False)
Dim x As Long
Dim i As Long
Dim s as String
.Destination = wdSendToPrinter
.SuppressBlankLines = True
'get the record count of the datasource
.ActiveRecord = wdLastRecord
x = .ActiveRecord
'set the activerecord back to the first
.ActiveRecord = wdFirstRecord
'loop the datasource count and merge one record at a time
For i = 1 To x
.DataSource.FirstRecord = i
.DataSource.LastRecord = i
I try to replace the "XXXXXXXXXXXXXX" line with .datasource.fields("ID") to retrieve the value of the "ID" for each record to save as my filename, however .datasource.fields("ID") always returns only the ID value of the first record in the datasource, although I have already change the id of the first record.
What can I do to get the values correctly?