Solved

Reading the values of a datasource

Posted on 2004-09-14
3
589 Views
Last Modified: 2006-11-17
Hi,

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

 With objDoc.MailMerge
   
   .Destination = wdSendToPrinter
   .SuppressBlankLines = True
   
   'get the record count of the datasource
   With .DataSource
     .ActiveRecord = wdLastRecord
     x = .ActiveRecord
     'set the activerecord back to the first
     .ActiveRecord = wdFirstRecord
   
   End With
   
   'loop the datasource count and merge one record at a time
   For i = 1 To x
     .DataSource.FirstRecord = i
     .DataSource.LastRecord = i
XXXXXXXXXXXXXX
     .Execute Pause:=True
    Next i
 End With
 
 objDoc.Close (False)

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?
0
Comment
Question by:sata
  • 3
3 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 125 total points
ID: 12061632
for the next record you could try

.DataSource.ActiveRecord = wdNextRecord
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12061638
something like

 .DataSource.LastRecord = x

For i = 1 To x
     .Execute Pause:=True
     .DataSource.ActiveRecord = wdNextRecord
Next i
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12061648
see also the last post one this thread
http://www.vbaexpress.com/forum/showthread.php?t=76&page=1
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question