Results 1 to 12 of 12

Thread: Any know how to do MailMerge ? Urgently required

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16

    Any know how to do MailMerge ? Urgently required

    Hi,

    Does anyone know how to perform Mail Merge to Word template in VB.Net.?
    Basically after filling in my dataset. I would like to open the word temaplet, loop through the dataset, fill in the value to the book marks created in the template and loop back again.

    If I have 100 records in my dataset, I would like t have 100 pages of one document rather 100 word documents of one page each.

    I hope I make sense, an early response will be very much appreciated.

    Thanks in advance

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    can you upload the word template?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    Well it could be any word template I suppose.

    I would be given user a choice to what template to select and what fields from SQL database to retreive. And then perform the Mail Merge action to Word temaplate whatever the user has selected.

    If you have any example for this action would be really helpfull.

    Thanks

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ahh.. I see what your after.

    hmmm.... let me think about it. I could do in in VB6...so im sure it can be done in .net

    are you using Office 2000? XP? (I only have 2000 but that should be able to be used with office XP)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok..have you been able to even launch word from vb.net?


    the only thing I have found is a download that included a file called: Interop.Word.dll
    http://msdn.microsoft.com/library/de...mateoffice.asp
    (download the sample)


    this file is a needed reference to even get the
    Dim wrd as New Word.Application
    to work?
    not sure why I couldnt get it otherwise....
    unless someone else has figured this out....
    Last edited by Static; Mar 6th, 2003 at 09:43 PM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    wwoops.. "Pay no atention to theman behind the curtain"
    lol

    I found them in the references
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok... heres a start:

    VB Code:
    1. Dim wrd As New Word.Application
    2.         wrd.Visible = True
    3.         wrd.Documents.Add()
    4.  
    5.         wrd.ActiveDocument.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels
    6.         wrd.ActiveDocument.MailMerge.OpenDataSource(Name:="[b]C:\Path to datafile.doc[/b]", PasswordDocument:="", WritePasswordDocument:="", SQLStatement:="" & "", Connection:="", LinkToSource:=True)
    7.         wrd.ActiveDocument.DataForm()
    8.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="Title")
    9.         wrd.Selection.TypeText(Text:=" ")
    10.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="FirstName")
    11.         wrd.Selection.TypeText(Text:=" ")
    12.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="LastName")
    13.         wrd.Selection.TypeParagraph()
    14.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="Address1")
    15.         wrd.Selection.TypeParagraph()
    16.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="City")
    17.         wrd.Selection.TypeText(Text:=", ")
    18.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="State")
    19.         wrd.Selection.TypeText(Text:=" ")
    20.         wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="PostalCode")
    21.         wrd.Selection.TypeParagraph()
    22.  
    23.         With wrd.ActiveDocument.MailMerge
    24.             .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
    25.             .MailAsAttachment = False
    26.             .MailAddressFieldName = ""
    27.             .MailSubject = ""
    28.             .SuppressBlankLines = True
    29.             With .DataSource
    30.                 .FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
    31.                 .LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
    32.             End With
    33.             .Execute(Pause:=True)
    34.         End With


    the best thing to do....
    record a macro... then do what you need...then view the code.
    thats almost what I did above...it is close to working (the data of my 3 customers disappeared but..)

    let me know if you need more help
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    Thanks a lot man.
    I was facing the problem, I couldn't get Dim wrd As New Word.Application this working in .Net and thanks for your insight.
    I will give it a shot and will let you know how it goes.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    I tried adding the word refernce libary but it won't let me add it, it fails by displaying an error message that failed to conver to type library, please have a look at the attachment. It's a screen shot of the error message.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    ooops here is the attachment

  11. #11
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    lol...where is the attachment?
    Are you adding the Microsoft word 9.0 etc... reference?


    well..Try downloading the example from Microsoft...

    and swipe the Interop.Word.dll from it.
    then use browse to add it as a reference...that should work
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    16
    It seems like it worked just by grabbing the word.dll and adding to my project.

    I'll proceed with my application and will let you know the progress.

    Thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width