Change Default Value of Text Box - InfoPath Dev
in

InfoPath Dev

Change Default Value of Text Box

Last post 04-27-2009 04:44 PM by greenant. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-26-2009 04:54 PM

    Change Default Value of Text Box

    Hi there,

    I have an Infopath form, which uses VB code to perform several advanced functions.

    I can get most of what I want, but am stuck on changing the default value of 3 rich text boxes.

    The default value should change when I click a button on the form.

    The value to enter comes from a string variable which I have already set up.

    Any ideas of how to go about this?

    Thanks for any help you can throw my way.

  • 04-26-2009 09:53 PM In reply to

    Re: Change Default Value of Text Box

     

    Hi and welcome to forums,

    You have two ways.

    a. Store the string variable in to a hidden field in the form. And add a rule to the button to set the value. Follow the below steps to do that.

        1. Go to button properties.

        2. Click on Rules.

        3. Click Add then click Add action.

        4. Select ‘set a field's value' in action drop down, select rich text field in Field, select string value field in Value.

        5. Click Ok until all the windows gets closed.

    b. Add a button click event and store the string variable in to rich text field.

    Swathip
    www.ggktech.com
  • 04-27-2009 04:40 PM In reply to

    Re: Change Default Value of Text Box

    Thanks for the reply.
    I have sorted the problem out ... kind of.

    I was too busy looking outside the square to solve my problem, when really it was much simpler.

    All I had to do was figure out the code to assign a value to the text field. It didn't need to be the default value at all.
    I was at one point hoping to achieve this without using code, and thought the default value was the only way to achieve it without code.

    As it turned out I needed code for something else, so once I got into the coding of it, setting the value worked

    My only issue now is finding how to put a line break in using code... seems simple... but it isn't.

    Anyway, in case this helps others, here is the code for adding the text to a field through code.

    Dim field1 As String
    Dim field2 As String
    Dim xNav As XPathNavigator = Me.CreateNavigator()
    Dim ns As XmlNamespaceManager = Me.NamespaceManager

    field1 = field1 & field2 & System.Environment.NewLine                       '   The NewLine bit does not work. Am looking at a way to add a line break to a text box through code...
    xNav.SelectSingleNode("/my:MyFields/my:Text_Field", ns).SetValue(field1)

  • 04-27-2009 04:44 PM In reply to

    Re: Change Default Value of Text Box

    Actually, all you really need is:

    Dim field1 As String = "text"
    Dim xNav As XPathNavigator = Me.CreateNavigator()
    Dim ns As XmlNamespaceManager = Me.NamespaceManager

    xNav.SelectSingleNode("/my:MyFields/my:Text_Field", ns).SetValue(field1)

    The other stuff was related to my project.

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