View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Checkboxes on mailmerge recipients list

You probably need something like the following:

---------------------------------------------
Sub x()
Dim lLastRecord As Long
With ActiveDocument.MailMerge.DataSource
.ActiveRecord = wdLastDataSourceRecord
lLastRecord = .ActiveRecord
.ActiveRecord = wdFirstDataSourceRecord
Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included)
Do Until .ActiveRecord = lLastRecord
.ActiveRecord = wdNextDataSourceRecord
Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included)
Loop
End With
End Sub
---------------------------------------------

But I can't remember which version of Word first had wdLastDataSourceRecord
etc. You also need to consider the possibility that with some data sources,
Word may not actually be able to determine the number of the last record
without reading the entire data source, e.g. if the data source is an OLE DB
source with a "forward only cursor". Ther may also be problems in a
multi-user environment if someone adds or deletes records while you iterate
through them (I really do not know what Word does in that case)/

Although you can /set/ .ActiveRecord to the special values like
wdLastDataSourceRecord , you can't compare .ActiveRecord to them because in
that case VBA thinks you are trying to compare .ActiveRecord with a negative
integer. Personally, I think this confusion of actual numeric values and
symbolic values is a very poor way to do things.
--
Peter Jamieson
http://tips.pjmsn.me.uk

"Steffen Grellmann" wrote in message
...
Hi Peter,

thank you for replying.

On Wed, 12 Dec 2007 09:18:49 -0000, "Peter Jamieson"
wrote:

Roughly speaking the checked/unchecked states of these boxes correspond to
the value of ActiveDocument.MailMerge.DataSource.Included for the
ActiveRecord.


This was exactly what I wanted to know for getting started on this
matter. Thank you!

I just want to give you a short response before I'm getting deeper
into it.

In other words, if you want to set or examine the checkbox value, you have
to navigate to the record you want then examine or modify the value of
.Included.


OK, I have checked this but it's not working that simple as it is
described in the F1 help.

However,
a. it isn't particularly easy to manipulate the .ActiveRecord reliably,
in
the general case (the facilities for doing this are a bit weird, and if
you
do it one way, you'll find that when you iterate through the records, you
will not even see the ones where Included is set to False)


It seems tricky and buggy. I will do some more testing and give you an
response.

b. my recent tests in this area have tended to hang Word.

ACK!

Kind regards,

Steffen