Re: Single record merging



Rather than simply running Word from the command line with a parameter, can you automate it?

In essence Word lets you specify the records you want to merge in three different ways:
a. For some types of merge you can use { SKIPIF } fields in the body of the document. To do that you would have to alter the document itself before you merged, and Word itself would iterate right through your data source. So lots of problems there.
b. using an SQL query that is built when you select the data source, or which Word modifies when you set sort and filter options in Query Options, or which you provide as a parameter to Word's OpenDataSource method, or which you provide by setting the .QueryString property of the MailMerge.Datasource object
c. by setting MailMerge.Datasource.Included to false for every record e.g. using .SetAllIncludedFlags Included:=False, then navigating to the record you want, setting its Included flag to True

(Another way of course would be if you could set up a table that had one record that specified the key of the record you needed, and use a query/view to get the record you wanted. Then you wouldn't need to change anything in Word. But there can be problems with that).

In essence, if you know what query you need to use (complete with the WHERE clause that specifies the single record) you probably need to use (b), which is arguably the simplest option. If you do not know precisely what query has been specified then you could either
d. inspect .Querystring and try to modify its WHERE clause or
e. you would need at least to know the name(s) of the data sources unique key fields, in which case you could probably use (c).

Then you specify the destination (printer, new document, whatever) and use the MailMerge.Execute method to do the merge and so on.

Sorry I can't give you a chunk of code that just does it...

When automating Word MailMerge, you will probably also have to take account of the following KB article:

http://support.microsoft.com/kb/825765/en-us


--
Peter Jamieson
http://tips.pjmsn.me.uk

"Peter Ambrose" <Peter Ambrose@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:D925C63C-7652-4B43-9525-72A98E175D70@xxxxxxxxxxxxxxxx
I have a SQL database - I want to merge just a single record from it.

How do I select a particular from within Word, simply, ideally driven not
from within the word document? i.e. I need to pass word a record-id on
launching it, run a macro which then mailmerges just that record?

Thanks

Peter

.



Relevant Pages

  • MS Access/VBA Question - Using Multiple combo Boxes to Search on a Form
    ... -I have a form with several combo boxes and several text ... a button is clicked which launches a new form (frmResults). ... frmResults is bound to a query, the criteria of which is set to the ... specify anything for a particular field. ...
    (microsoft.public.office.developer.vba)
  • Re: ASP / Access: use of same table twice in one query
    ... are in the same table and I need them both in one query. ... I agree it is better to specify the fields I need in the select statement, ... >> The data is stored in an Access database. ... > quicker response by posting to the newsgroup. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Query records with single Dates Automatically
    ... both queries pull from the same table. ... -- Two Tables Attendees and Visits ... Please copy and post the SQL of your query. ... I have to find a way to specify ...
    (microsoft.public.access.queries)
  • RE: build an if statement with conditional parameters
    ... This is my modified code, no errors, but like I said, I can query with just ... Dave Hargis, Microsoft Access MVP ... "David Pelizzari" wrote: ... specify a date, and leave the site blank, and get nothing back, if I specify ...
    (microsoft.public.access.queries)
  • Re: Dynamic properties and query option
    ... Make sure the connection you specify ni the Query of the DP task is poing to ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) ...
    (microsoft.public.sqlserver.dts)