Click here to Skip to main content
15,914,452 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Prepare Templates & Mail Pin
Dave Kreskowiak27-Aug-07 5:45
mveDave Kreskowiak27-Aug-07 5:45 
GeneralRe: Prepare Templates & Mail Pin
Trupti Mehta27-Aug-07 19:32
Trupti Mehta27-Aug-07 19:32 
GeneralRe: Prepare Templates & Mail Pin
Dave Kreskowiak28-Aug-07 1:30
mveDave Kreskowiak28-Aug-07 1:30 
GeneralRe: Prepare Templates & Mail Pin
Trupti Mehta28-Aug-07 1:55
Trupti Mehta28-Aug-07 1:55 
GeneralRe: Prepare Templates & Mail Pin
Dave Kreskowiak28-Aug-07 3:31
mveDave Kreskowiak28-Aug-07 3:31 
GeneralRe: Prepare Templates & Mail Pin
Trupti Mehta28-Aug-07 19:20
Trupti Mehta28-Aug-07 19:20 
GeneralRe: Prepare Templates & Mail Pin
Dave Kreskowiak29-Aug-07 12:32
mveDave Kreskowiak29-Aug-07 12:32 
GeneralRe: Prepare Templates & Mail Pin
Trupti Mehta4-Sep-07 23:14
Trupti Mehta4-Sep-07 23:14 
Hi Dave,

Dave, thanks for your help so far. This is not just replacing text in RichTextBox. As mentioned earlier, RTB is used to just create letters. Actual Mail Merge is done later, seperately. If it was just replacing text once, thats not a big deal at all. I really tried very hard, looked on net a lot. But still can't find proper way out to replace the text for the same letter for all records in the dataset. Letter is written using RTb, saved, text like <<companyname>>, etc are added in the letter. On selection of letter and customers selected, This is the code that is fired to perform actual Mail Merge.

<br />
    Private Sub PerformMailMerge()<br />
        Dim wApp As New Word.Application<br />
        Dim wDoc As Word.Document<br />
        Dim wMailMerge As Word.MailMerge<br />
<br />
        wDoc = wApp.Documents.Open(Me.CapFileName)<br />
        wApp.Visible = True<br />
<br />
        wMailMerge = wDoc.MailMerge()<br />
        wMailMerge.CreateDataSource(mDs)<br />
<br />
        Dim i As Integer<br />
        Dim str As String = ""<br />
        Dim addThe As Boolean<br />
<br />
        Dim row As DataRow<br />
        For i = 0 To mDs.Tables(0).Rows().Count() - 1<br />
            MsgBox("Row of " + myDG.Rows(i).Cells(1).ToString())<br />
            If (myDG.Rows(i).Cells("Select").Selected() = True) Then<br />
                row = mDs.Tables(0).Rows(i)<br />
                str = row.Item("name").ToString()<br />
                ' If name is not present, refer to The Propriertor<br />
                If (String.IsNullOrEmpty(str)) Then<br />
                    'Replace("<<Title>>", "The")<br />
                    'Replace("<<ContactName>>", "Propriertor")<br />
                    addThe = True<br />
                Else<br />
                    'Replace("<<Title>>", row.Item("namePrefix").ToString())<br />
                    'Replace("<<ContactName>>", row.Item("name").ToString())<br />
                    addThe = False<br />
                End If<br />
<br />
                'Replace("<<CompanyName>>", row.Item("CompanyName").ToString())<br />
                'Replace("<<Add1>>", row.Item("Add1").ToString())<br />
                'Replace("<<Add2>>", row.Item("Add2").ToString())<br />
                'Replace("<<Add3>>", row.Item("Add3").ToString())<br />
                'Replace("<<City>>", row.Item("City").ToString())<br />
                'Replace("<<County>>", row.Item("County").ToString())<br />
                'Replace("<<Code>>", row.Item("Code").ToString())<br />
<br />
                'Replace("<<Date>>", Date.Today)<br />
                MsgBox("Added The " + addThe + " Or Name to " + row.Item("CompanyName").ToString())<br />
            End If<br />
        Next<br />
<br />
        ' Perform Mail Merge<br />
        wDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument<br />
        wDoc.MailMerge.Execute()<br />
<br />
        ' Close the original letter<br />
        'wDoc.Saved = True<br />
        'wDoc.Close()<br />
<br />
        '' Release References<br />
        'wApp = Nothing<br />
        'wDoc = Nothing<br />
        'wMailMerge = Nothing<br />
    End Sub<br />


As you advised earlier, I had added tags like <<companyname>> in the rtf file while creating letter. To do the mail merging stuff, I found this the only way out. I believe you can help me out. I have everyhting with me, just don't know how to so it. I agree something is still incorrect and missing in this code.

Please help me and let me know if what I am doing is right or am in any wrong path. Please my deadline is on, and got to finish this. I request you and hope, you will help.






Thanks

Terry

GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Dave Kreskowiak5-Sep-07 2:20
mveDave Kreskowiak5-Sep-07 2:20 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Trupti Mehta5-Sep-07 4:09
Trupti Mehta5-Sep-07 4:09 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Dave Kreskowiak5-Sep-07 14:07
mveDave Kreskowiak5-Sep-07 14:07 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Trupti Mehta5-Sep-07 17:36
Trupti Mehta5-Sep-07 17:36 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Dave Kreskowiak6-Sep-07 1:37
mveDave Kreskowiak6-Sep-07 1:37 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Trupti Mehta6-Sep-07 17:31
Trupti Mehta6-Sep-07 17:31 
GeneralRe: Prepare Templates &amp;amp;amp; Mail Pin
Dave Kreskowiak7-Sep-07 1:49
mveDave Kreskowiak7-Sep-07 1:49 
QuestionAutomate Excel Using vb 6.0 Pin
jamesrajesh27-Aug-07 1:31
jamesrajesh27-Aug-07 1:31 
AnswerRe: Automate Excel Using vb 6.0 Pin
Dave Kreskowiak27-Aug-07 5:42
mveDave Kreskowiak27-Aug-07 5:42 
Questionhow to write something "does not equal" something else. Pin
KOTO-G27-Aug-07 1:09
KOTO-G27-Aug-07 1:09 
AnswerRe: how to write something "does not equal" something else. Pin
Christian Graus27-Aug-07 1:58
protectorChristian Graus27-Aug-07 1:58 
GeneralRe: how to write something "does not equal" something else. Pin
jamilkhan00727-Aug-07 19:53
jamilkhan00727-Aug-07 19:53 
AnswerRe: how to write something "does not equal" something else. Pin
Johan Hakkesteegt30-Aug-07 0:09
Johan Hakkesteegt30-Aug-07 0:09 
QuestionError number description Pin
sacheesach27-Aug-07 0:53
sacheesach27-Aug-07 0:53 
AnswerRe: Error number description Pin
Dave Kreskowiak27-Aug-07 3:21
mveDave Kreskowiak27-Aug-07 3:21 
Questiondelegate Pin
Ahamed Azeem27-Aug-07 0:30
Ahamed Azeem27-Aug-07 0:30 
GeneralRe: delegate Pin
Christian Graus27-Aug-07 1:04
protectorChristian Graus27-Aug-07 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.