Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Edit-Attach second doc (VB6)

    With the following code, a claim warranty template (SEL-TR.doc) is edited and attached to an email.
    The process works fine.
    I also need to edit another doc (WIN-Invoice.doc) and attach that also.

    I edited the code after the End with statement but the first doc is being over written.
    Any help would be appreciated.

    <pre>Private Sub cmdClaimFom_Click()
    On Error GoTo ErrHandler
    Dim oWord As Object
    Dim oDoc As Object
    Dim strPath As String

    'sRTF represents the rich text formatted string to paste into Word
    Dim sRTF As String
    sRTF = Me.RichTextBox1.TextRTF
    'Copy the contents of the Rich Text to the clipboard
    Dim lSuccess As Long
    Dim lRTF As Long
    Dim hGlobal As Long
    Dim lpString As Long
    lSuccess = OpenClipboard(Me.hwnd)
    lRTF = RegisterClipboardFormat("Rich Text Format")
    lSuccess = EmptyClipboard
    hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
    lpString = GlobalLock(hGlobal)

    CopyMemory lpString, ByVal sRTF, Len(sRTF)
    GlobalUnlock hGlobal
    SetClipboardData lRTF, hGlobal
    CloseClipboard
    GlobalFree hGlobal

    'Input Boxes
    Dim strPart As String
    strPart = InputBox("Part Description", "What Part Is This ?")
    Dim strMan As String
    strMan = InputBox("Please Enter A Vehicle Manufacturer", "What Make Of Car Is This ?")
    Dim strMod As String
    strMod = InputBox("What Model Is This ?", "Reported Fault")
    Dim strFault As String
    strFault = InputBox("What Kind Of Fault Is This ?", "Reported Fault")
    Dim strWin As String
    strWin = InputBox("Please Enter A Valid WIN No", "Internal Invoice No:")

    strPath = "C:MM-UtilitiesTech-Report" & "-" & strWin & "-" & txtPartNo & "-" & strMan & ".doc"

    Set oWord = CreateObject("word.application")
    Set oDoc = oWord.documents.Add("C:MM-UtilitiesSEL-TR.doc")

    frmWait.Show

    With oWord.Selection.Find

    .Execute FindText:="#PN#", ReplaceWith:=Me.txtPartNo.Text, Replace:=2
    .Execute FindText:="#rptDate#", ReplaceWith:=Date, Replace:=2
    .Execute FindText:="#strPart#", ReplaceWith:=strPart, Replace:=2
    .Execute FindText:="#strMan#", ReplaceWith:=strMan, Replace:=2
    .Execute FindText:="#strFault#", ReplaceWith:=strFault, Replace:=2
    .Execute FindText:="#strWin#", ReplaceWith:=strWin, Replace:=2
    .Execute FindText:="#strMod#", ReplaceWith:=strMod, Replace:=2
    .Execute FindText:="#Picture#"
    oWord.Selection.InlineShapes.AddPicture FileName:=Me.txtWarrImg
    .Execute FindText:="#INDcomment#"
    oWord.Selection.Paste

    End With

    oDoc.SaveAs strPath
    oDoc.Close False
    Set oDoc = Nothing
    oWord.NormalTemplate.Saved = True
    oWord.quit
    Set oWord = Nothing
    Unload frmWait

    MAPISession1.SignOn
    With MAPIMessages1
    .SessionID = MAPISession1.SessionID
    .Compose
    .MsgSubject = "Technical Report For Part No " & txtPartNo & " - " & strWin
    .MsgNoteText = "Technical Report For Part No " & txtPartNo & " - " & strWin
    .AttachmentPathName = strPath
    .Send True
    End With
    exitHandler:
    On Error Resume Next
    MAPISession1.SignOff
    Exit Sub

    ErrHandler:
    If Err.Number = 32001 Then
    Resume Next
    End If
    Resume exitHandler

    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Edit-Attach second doc (VB6)

    You should create both documents before creating the e-mail, and use a second variable strPath2 for the path+name of the second one.
    When you are composing the e-mail message, you must increase the AttachmentIndex after specifying the first attachment:
    <code>
    With MAPIMessages1
    .SessionID = MAPISession1.SessionID
    .Compose
    .MsgSubject = "Technical Report For Part No " & txtPartNo & " - " & strWin
    .MsgNoteText = "Technical Report For Part No " & txtPartNo & " - " & strWin
    .AttachmentPathName = strPath
    .AttachmentIndex = .AttachmentIndex + 1
    .AttachmentPathName = strPath2
    .Send True
    End With</code>

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Edit-Attach second doc (VB6)

    Thank you Hans

    I hadn't realised it was that simple.

Posting Permissions

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