Saving query options in main document

S

Susan

I've created a main document for 5160 labels which I want
to use on a regular basis with a custom database. Within
Word, I can set the query options to sort by zip code and
it will do so with no problem. However, when I use that
Word main document from within the database, it does not
sort by zip codes. Basically, any time I use a different
data file, it clears out the query options. Can't I make
a query option/sort an integral part of the main document
so that no matter what data file I attach (as long as the
merge fields are the same) the sort will be honored?
 
P

Peter Jamieson

Can't I make
a query option/sort an integral part of the main document
so that no matter what data file I attach (as long as the
merge fields are the same) the sort will be honored?

Not just using the facilties provided by the Word user interface.

The only way to do this would be to use some VBA to "re-apply" the desired
sort sequence each time you connect to a new data source. Unfortunately, you
can't just specify "sort on the field named x" in VBA - you have to provide
the full SQL query, either in the SQLStatement parameter of the
OpenDataSource method, or by setting the QueryString property of the
Mailmerge Datasource. That's probably a lot simpler if you always know that
you are going to be using the same kind of data source (e.g. always a text
file, or always an Excel spreadsheet).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top