I am writing a vba app to automate a mail merge document. The doc is
connected to an access database. The datasource retrieves the data just
fine. Then I set all of the records include flags to false (thus excluding
them from the merge). Next I iterate through the list to include ones that
meet a criteria that the user has selected from a userform. If the criteria
is met, a function is called that sets the activerecord to the first record
(wdFirstRecord, I think). Then I use the find method to point the
activerecord to the correct record, and finally set the included property to
true. The problem is that neither the .activerecord = wdFirstRecord, nor the
Find method changes the record position, it remains at 1. Nothing I've tried
and nowhere I've looked has said anything about the records not being able to
move. Is there something in the connection string that can cause this, or
some property I'm not setting correctly?

There are more records in the set than just one, so that's not the problem.
Any help would be appreciated.

Re: Mail merge Datasource Will Not Change Records by Cindy

Cindy
Fri Sep 08 05:10:10 CDT 2006

Hi =?Utf-8?B?Sm9obg==?=,

> I am writing a vba app to automate a mail merge document. The doc is
> connected to an access database. The datasource retrieves the data just
> fine. Then I set all of the records include flags to false (thus excluding
> them from the merge). Next I iterate through the list to include ones that
> meet a criteria that the user has selected from a userform. If the criteria
> is met, a function is called that sets the activerecord to the first record
> (wdFirstRecord, I think). Then I use the find method to point the
> activerecord to the correct record, and finally set the included property to
> true. The problem is that neither the .activerecord = wdFirstRecord, nor the
> Find method changes the record position, it remains at 1. Nothing I've tried
> and nowhere I've looked has said anything about the records not being able to
> move. Is there something in the connection string that can cause this, or
> some property I'm not setting correctly?
>
I tend to not use the Include flags if at all possible. Note that the enumeratin
you're trying to use has two sets of record types: records in the data set, and
records available when Include flags have been set to false.

I *think* the problem you're having is that there ARE no available records as
the "first record" if all the Include flags have been set to false. I suspect
you may need to work with other way around: loop through each record,
one-by-one, and set the flag as appropriate.

Note: I don't know what kind of criteria your userform is capturing, but if it's
something you can check a field for, then using QueryString would be a LOT
faster than the approach you're working with...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)


Re: Mail merge Datasource Will Not Change Records by John

John
Fri Sep 15 09:29:02 CDT 2006

Thanks Cindy, you were right. When I worked at it the other way around and
excluded records instead of including them, it worked great.