Solved

Reading the values of a datasource

Posted on 2004-09-14
3
597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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