Free Support Forum -

Question concerning mailmerge


I’ll try to explain my question the best I can…

For a customer, I’m creating multiple documents with the mailmerge functions. One document needs to have two versions. One with things like date of birth, date of medical treatments, and more information considering doctors and patients (I.E. names, addresses, and the likes.), and another where those information considering doctors and patients is not visible, or replaced by (…).

The document with the data visible needs to be created first, then the user will change that document, and then, my application needs to somehow recognize those fields wich need to be replaced, and replace them, creating a second document. So basicly the first document needs to serve as a template for the secod document…

Is this possible?

Eric van der Hoek

Hello Erik,

Not sure if I understand things right. Mailmerge is about creating the template for some document. for example when you want to invite a hundred of people fo dinner you create one invitation template with mergefields where people's address and name should be. And then you generate actual invitations, quickly filling mergefields with the actual names and addresses from a datasource, such as dataset or datatable.

Now in your case, could you describe how your application will look like from user position. For example, "user chooses from multiple buttons on a screen what form he wants to edit, presses the button, gets a form with labels and textboxes, allowing him to input information, submits it and acquires the filled Word document file on his computer". Or something like that.

Also, please explain at what stage data considering doctors and patients should be substituted with (...). Is it for security reasons? Then, what data user actually changes?

Sorry for being so slow. I would be really grateful if you provide more detailed explanation of your task.

Lets see if I can clarify more.

I've developed an application in wich users register medical cases. From a user position, it goes something like this:

  1. - User adds a new medical case to the application. This data is stored in a sql2000 database
  2. - User can create documents. the documents created are populated by data from the database with a mailmerge function. (document version 1)
  3. - User reviews document, adds text concerning that specific case, and saves the document.(document version 2)
  4. - User has a meeting with some more people, going over the document again, and, if needed, makes changes (document version 3)
  5. - User wants to remove all relative data from that document (document version 3). data like Doctors name, address, Patients name, adresses, date of birth, date of death, and some relevant dates. this document is then saved as a new document, leaving version 3 unchanged. (document version 4), reviewed again, and converted to pdf, to be posted on a website.

I've almost got all the functionality required in this, but now I need to perfect step 5, the removal of that specific data.

I've tried a number of different approaches, currently, I'm able to save the document described in step 4, but with all the fields still linked (I use Word automation to prepare the mailmerge, but I simply never give the Merge.Execute command.) so now I'm left with replacing texts in bookmarks, and the bookmarks itself. When I try to replace the text in a bookmark with some other text, the word document somehow gets corrupted, and causes MS Word to crash.

I can't add the document or code at this moment in time, because I'm currently working at a different project.

I hope this makes more clear of what I need Aspose.Word to do for me. You would really help me if you can solve the "Word crashes" problem for me.

Thanks for your help,
Eric van der Hoek

Bookmarks sounds like a good way to go. If Aspose.Word produces a document that causes MS Word to crash, please post the document “as before” modified by Aspose.Word and how did you modify it so it starts crashing. We should be able to fix.

Thanks for the offer to fix it, but I found the problem ;) If the bookmark contains only a formfield, and you use Bookmark.Text = "new text";, it looks like you don't replace the entire formfield, leaving the start or end tag ( I can't see wich one) in place. This caused word to crash, or, when I opened and saved the doc using Aspose, looks like the entire document is made up of a faulty form field..

If this is something you are willing to look into, let me know, and I'm willing to mail the document, and the code I'm using. For privacy reasons, I will not post the document on a public forum..

Yes, you can send a private e-mail to any of the participants of the forum. Just find the post of the person you want to send message to and press the e-mail button in the bottom left.

Also, when you are making an attachment to your post - it is visible only to you and Aspose team, nobody else sees it.