Re: Imitating Mail Merge on server

From: William Morris (news.remove.this.and.the.dots_at_seamlyne.com)
Date: 06/02/04


Date: Wed, 2 Jun 2004 15:48:09 -0500

We do something similar in our app - it's based on the premise that at any
given moment we know which data (in this case, customers) is being worked
with. I'll give you a simple example:

--- letter ---

Dear #firstname#,

Thanks for your recent purchase. Sincerely,

#salespersonname#
Your Salesperson

--- end letter ---

--- table: LetterTokens --
tokenName varchar(255)
tokenSQL varchar(7000)

#firstname# SELECT cusFirstname FROM customers where cusNum = #cusnum#
#salespersonname# SELECT empFirstname FROM employees e INNER JOIN
                                customers c on e.employeeid = c.employeeid
                                where cusNum = #cusnum#

--- end table ---

The general process works like this:

First : open the tokens table into an array, adding an empty element on the
end for the eventual values, and concantenate each query together.
Second: run that query, using rs.open cxn, sqlString
Third: loop the array, plug in the current recordset value. set rs =
rs.nextRecordset, loop the array, and repeat until each recordset value has
been plugged in.
Fourth: open the letter, loop the array again, this time plugging the values
in with simple REPLACE statements.
Fifth: create a new file with the substitutions made and feed it to the
browser.

We have close to fifty tokens that we use in the application correspondence,
and there's no noticable lagtime. The only time there's a problem is if
someone puts in a token/query where the query hasn't been properly tested,
so the whole process fails. We've also recently added a token ~remover~
that replaces any unused sql tokens with a negative number so the query will
run, even if it doesn't return a value.

HTH,

 - Wm

-- 
William Morris
Product Development, Seritas LLC
Kansas City, Missouri
"Diane Yocom" <diane.yocom.nospam@seattle.gov> wrote in message
news:eSHD80BSEHA.2976@TK2MSFTNGP10.phx.gbl...
> I have an ASP intranet application that is required to produce Word
> documents merged with data from a database.  I originally looked at
> automating Word's mail merge capabilities, but nixed that idea since I
> learned it's not a good idea to try to automate Word on the server and I'd
> rather not have to worry about whether or not the user has Word on their
> machines.
>
> I, instead, decided to have the Word templates saved as RTF files and to
> write a parser/merger myself.  This was going fine, although made me a
> little nervous since Word produces such complicated RTF code, until we
> decided that we were going to combine multiple templates into one final
Word
> document with, potentiall, different header and footers for each
> section/template doc.
>
> I'm having a problem figuring out how to get sections inserted into the
> combined RTF doc, so I'm thinking perhaps I should rethink my
solution...Can
> anyone offer suggestions on how to produce database merged documents from
> templates created by users on a Web server?  We may have some budget, so
> third-party tools would be welcome, as well.
>
> Any suggestions would be greatly appreciated,
> Diane Y.
>
>


Relevant Pages

  • Re: Copying a table to an array
    ... You probably don't need a query, ... Dim rstRSet As Recordset ... table to enable data from the latter to be read into an array with GetRows. ... exercise has therefore to be repeated prior to each interrogation. ...
    (microsoft.public.access.formscoding)
  • Re: Mix/Max/Avg Help based on dynamic ranges
    ... Did you enter Biff's formula as an array? ... The query I gave you is dependent on your breaking out the ranges as Biff ... Where Nums are the values to avg based on the head count range. ... deemed optimal for building device profiles based on locn size and device ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Copying a table to an array
    ... "Peter Hibbs" wrote: ... You probably don't need a query, ... Dim rstRSet As Recordset ... table to enable data from the latter to be read into an array with GetRows. ...
    (microsoft.public.access.formscoding)
  • Re: Subquery Confusion
    ... Then I got this crazy idea that an Array can only contain a maximum ... number of characters, ... Then I decide that maybe I'm completely wrong with my query, ... it out of Excel VBA and spit it into Microsoft SQL Server Management ...
    (microsoft.public.excel.programming)
  • Re: C# 2.0 + MS Access == Error
    ... All the tokens are perfectly fine. ... If you are completely sure that the query tokens are all correct, ... DataTabledatatables, Int32 startRecord, Int32 maxRecords, String ... startRecord, Int32 maxRecords, String srcTable, IDbCommand command, ...
    (microsoft.public.dotnet.languages.csharp)