Form send per E-Mail with a Button with Code behind - how? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Form send per E-Mail with a Button with Code behind - how?

Last post 11-02-2010 12:05 PM by Hilary Stoupa. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-29-2010 07:03 AM

    Form send per E-Mail with a Button with Code behind - how?

    Hi,

     I have the following problem. I designed an Infopath form, with an Access-DB primary connection. Additionally I need to send this form per Button per E-Mail to a definied adress.

    With an Access-DB Connection as primary connection, I can't use the normal E-Mail Connection from Infopath to send the form. (Only one send connection is allowed.)

     So I have to look to solve this problem with VB code.

     I found at the following link this example:

    http://msdn.microsoft.com/de-de/library/microsoft.office.infopath.mailenvelope.aspx

    Code:

    Imports Microsoft.Office.InfoPath
    Imports System
    Imports System.Windows.Forms
    Imports System.Xml
    Imports System.Xml.XPath
    Imports mshtml
    Imports Microsoft.Office
    Imports Microsoft.VisualBasic
    Imports System.Web.Mail
    Imports System.Web

    Namespace VA

        Public Class FormCode

            Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup
                AddHandler EventManager.FormEvents.Submit, AddressOf FormEvents_Submit
                AddHandler DirectCast(EventManager.ControlEvents("CTRL16_7"), ButtonEvent).Clicked, AddressOf CTRL16_7_Clicked
                AddHandler DirectCast(EventManager.ControlEvents("CTRL27_4"), ButtonEvent).Clicked, AddressOf CTRL27_4_Clicked
                AddHandler DirectCast(EventManager.ControlEvents("CTRL28_4"), ButtonEvent).Clicked, AddressOf CTRL28_4_Clicked
            End Sub

            Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)

            End Sub

            Public Sub CTRL16_7_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
                ' Form send with Mail

               ' Set a reference to MailEnvelope object.
      Dim myEnvelope As MailEnvelope  = _
         Me.Application.ActiveWindow.MailEnvelope;

      ' Check to see if form is open in Outlook.
      If (myEnvelope.Available) Then
         ' Specify addresses, subject, and introduction.
         myEnvelope.To = "someone@example.com"
         myEnvelope.CC = "someone@example.com"
         myEnvelope.BCC = "someone@example.com"
         myEnvelope.Subject = "Open this form"
         myEnvelope.Introduction = "InfoPath is required to edit this form."

      ' Include form template with form.
         myEnvelope.EmailAttachmentType = EmailAttachmentType.XmlXsn

         ' Display form with e-mail envelope.
         myEnvelope.Visible = True
      Else
         ' The form is open in Outlook, and code will not run.
         MessageBox.Show("This form is open in Outlook.")
      End If

            End Sub

        End Class

        'Deklaration
       Public MustInherit Class MailEnvelope
            Dim instance As MailEnvelope
        End Class

    End Namespace

    ==========================================

    ==========================================

    ==========================================

    The first problem ist the semicolon (;) at

    Me.Application.ActiveWindow.MailEnvelope;

    which gets a blue underscore for a code failiure

    Then all the myEnvelope variables have also a blue underscore.

    ____________________________________________________

    I tried a lot of things, but I don't get rid of this code failiures. Now I have 8 hours of try'n behind me and hope someone can help me here with this Visual Basic Class. I only want to send the actual form with all user made entrys to an E-Mail adress.

    Regards

    Marco

  • 10-29-2010 07:25 AM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    hi, first remove the semicolon, it's not necessary on VB.

  • 10-29-2010 08:07 AM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    Can't you change your submit options to use rules and then use a rule to first submit to Access and a second rule to submit to your email connection? I really don't think you need to write code for this.
    Hilary Stoupa

  • 10-29-2010 09:07 AM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    Hilary is right you probably set your button action to "Submit" if you set it to "rules and custom code", you can set many submit rules in this way.

  • 10-31-2010 11:31 AM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    O.K. thanks for comments so far.

    I know that a semicolon is not a typical sign for VB so I had tried to remove the semicolon before, but then rest of the code is then also wrong and the whole row before the semicolon (Me.Application.ActiveWindow.MailEnvelope). So that isn't the solution.

     Rules were that what I tried before I started to program a code solution. But I didn't got that rules to work. Now where you mentioned to me, that rules should can handle 2 different data connections, I gave them another try. Sadly I don't get my rules to work.

     I only want a very very easy configuration.

     Rule 1:

    IF

     field:Number1 (from my Access-DB Data Fields) is empty

    Then Action

    Send to Data Connection - E-Mail

    Rule 2:

    IF

     field:Number1 (from my Access-DB Data Fields) is not empty

    Then Action

    Send to Data Connection - Database

    ______

    Unless if the Field Number1 is empty or not, the form allways sends an email. I can't use the main data connection to my database.

    I tried to change the order of the rules processing. I tried to activate the checkboxes at "end the rules processing if this rule fits and was executed". I tried a MsgBox instead of the E-Mail send, but then if I have NOT a number in my field, the message box appears and data is send to Access. But after getting the MsgBox, the rules should stop processing, because I activated the checkbox, and the rule for sending to Access is not true.

    I think something important must not be working with my rules, you have any ideas and suggestions for me please?

    I'm also further interessted to get the E-Mail send VB code for a formular.

  • 11-02-2010 08:29 AM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    Anyone have an idea for me? I don't get this rules working.
  • 11-02-2010 12:05 PM In reply to

    Re: Form send per E-Mail with a Button with Code behind - how?

    Generally, when rules don't work the way I expect they will, the problem is that a field is not the value I think it is. Add a rule to field:Number1 that will display its value when you change it, as well as actions to your submit rules to display the value of the field the conditions are based off of. This may help you see where your logic error is. Is the condition that the field is blank or the field is not blank? Or present or not present? I don't see "empty" as an option when I try to set a rule condition.
    Hilary Stoupa

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