Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating Your Own Merge Engine (Word2000/.NET)

    Here's the basic gist of the project I'm currently working on.... over 600 templates. Big huge database that was custom written. Currently all 600 templates are done using Word's mergefields. Obviously there are some big problems with this implementation -- not only does the actual ".DOC" file have to get opened in order for the merge to run but mergefields are limited in what they can and cannot do so, for example, in one case a "new merge document" was created because one page had to have a different margin based on the value of a field. So many of these 600 templates may go away when I can handle problems like this via VBA. They were originally created under Word97, moved to Word2000 and now will not run under XP. The firm is trying to move to XP across the board and hopefully Office 11 in the future.

    So, I have created a .NET class library (DLL) which is my data tier. I call my DLL from within my template and display a beautiful dialog to the user, prefilled with the information from the db based on the fileno they enter and prompting them for the additional information the template needs. For each text box on my dialog, I use the tag property and give it the name of the "merge marker" I am using in the document. So, for example, The FileNO text box will have a tag of xMyCompanyFileNo. Once the user hits the OK button, I simply iterate through all the text boxes on the form, read the tag value, do a search/replace of all the merge markers in the document.

    This works great and is very fast.... but.... I have hundreds of templates that don't have user input necessary and they do not want to see the database information. All they want is to select their template and have their merge run. What I'm trying to come up with is the best logical approach to dealing with this. In the past I've simply created a "DoMarkers" function in my DLL and iterated through all the merge markers available, if it exists, fill it otherwise you just move on to the next. I think I need another idea though because I have 1,000 possible merge markers. The hope is to allow users to create their own merge marked documents, click a button and boom it populates.

    Can anyone think of the fastest approach to iterating through the possible merge markers or do I just have to bite it and do all 1,000 and hope the timelag isn't horrendous.... I think it might be faster if I used bookmarks but if I have a piece of data used multiple times then this creates an issue to deal with.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating Your Own Merge Engine (Word2000/.NET)

    What about using a Document Property or Document Variable in your template to store a delimited list of the fields you want from the database? Parsing that has got to be faster than examing all the merge fields at run time. If that isn't there, you pop up the dialog.

    Oops: I just read the part about having users create their own templates. I guess you'll need to give them a tool that builds the DocProp/DocVar for them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •