Help..Email Button using VBscript on Form? - InfoPath Dev
in

InfoPath Dev

Help..Email Button using VBscript on Form?

Last post 01-15-2009 01:43 AM by paralyzedcitizen. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-22-2006 09:12 AM

    Help..Email Button using VBscript on Form?

    Does anyone know how to create a button on a form using VB that essentially calls the 'Send to Mail Recipient' option? I've seen code that works for Jscript (see below), but nothing for VB.

    Thanks

    function SendEmailBtn::OnClick(oEvent)
    {
    createEmail();
    }



    function createEmail()
    {
    var xmlContributors =
    XDocument.DOM.selectNodes("/iss:issue/iss:contributors/iss:contributor");
    var xmlContributor;
    var xmlTitle = XDocument.DOM.selectSingleNode("/iss:issue/iss:title");
    var rgRecipients = new Array();

    while (xmlContributor = xmlContributors.nextNode())
    rgRecipients.push(getNodeValue(xmlContributor.selectSingleNode("iss:emailAddressPrimary")));

    try
    {
    var oEnvelope = XDocument.View.Window.MailEnvelope;

    oEnvelope.To = rgRecipients.join("; ");
    oEnvelope.Subject = getNodeValue(xmlTitle);
    oEnvelope.Visible = true;
    }
    catch (ex)
    {
    XDocument.UI.Alert(ex.description);
    }
    }
  • 07-28-2006 12:14 PM In reply to

    Re: Help..Email Button using VBscript on Form?

    Hey,

    There are a couple of ways..........

    The ShowMailItem can be used and you can set the To, CC, BCC, Subject and Body of the email message.

    Function OpenEmailWindow(eventObj)
    'Opens an email window with prefilled subject line and with form as xml attachment (no HTML version).
    On Error Resume Next
    If Err.number <> 0 Then
    eventObj.ReturnStatus = False
    Exit Function
    End If

    Set oFormNum = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormNumber")
    Set oFormName = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormTitle")
    formSubj = oFormNum.text & " - " & oFormName.text
    XDocument.UI.ShowMailItem "", "", "", formSubj,""
    eventObj.ReturnStatus = True
    Exit Function
    End Function

    Or if you have MS Outlook 2003, you can code directly to it:

    Sub CreateMailMsg(sTo, sCC, sBCC, sSubj, sBody, sAttachFile)
    'purpose creates an outlook message and attaches the MHT file created above
    'date 04/19/2006

    Dim objOlApp
    Dim objItm
    Set objOlApp = CreateObject("Outlook.Application")
    Set objItm = objOlApp.CreateItem(olMailItem)

    With objItm

    .To = sTo
    .CC = sCC
    .BCC = sBCC
    .Subject = sSubj
    .Body = sBody
    .Attachments.Add sAttachFile
    .Display

    End With

    End Sub

    Hope that helps,
    Mary
  • 01-15-2009 01:43 AM In reply to

    Re: Help..Email Button using VBscript on Form?

     I used your second method and got an error. It said it couldn't create an object.

     How come?

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.