Add new row with VBScript - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Add new row with VBScript

Last post 11-03-2008 02:49 AM by GazM. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 10-29-2008 07:37 AM

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Add new row with VBScript

    Hi

    I've been scouring the forum and elswhere for a solution to this for the past few days. All I need to do is add a blank row to a repeating table. The following code has been cribbed from other sources on the forum but I am having trouble getting it to work.

     Sub msoxd_my_field1_OnAfterChange(eventObj)

    'Add new row to repeating table programmatically

    Dim newxmlstring, oXML, oParent

    'Build XML needed for empty node

    newxmlstring = "<my:group4><my:field1></my:field1></my:group4>"

    'Create a new empty node

    Set oXML = XDocument.CreateDOM()

    oXML.loadXML(newxmlstring)

    'Define Parent

    Set oParent = XDocument.DOM.selectSingleNode("/my:myFields/my:group3/my:group4")

    'set node 'Set oNode = oXML.documentElement

    'Add new node to parent as XML

    oParent.appendChild(oXML.documentElement) --------- code fails here Error: Invalid procedure call or argument

    End Sub

    Can anyone help or point me towards a solution?

    Thanks

    Gary

  • 10-29-2008 09:27 AM In reply to

    Re: Add new row with VBScript

    Have you tried using the ExecuteAction method?

     Sub CTRL5_5_OnClick(eventObj)
     XDocument.View.ExecuteAction "xCollection::insert", "group2_1" 
     End Sub

    The second argument ("group2_1" in this case) refers to the XmlToEdit identifier for the repeating control and can be found on the Advanced tab of the repeating control's properties.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-30-2008 02:52 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add new row with VBScript

    Thanks Jimmy

    That works fine with a button (OnClick event) and I get a new blank row. When I try it with an onAfterChange event I get the following error:

    "The number of calls to the OnAfterChange event for a single update in the data exceeded the maximum limit."

    and it inserts 15 blank rows. My coding skills are limited. Any thoughts on how I can limit this to one row?

    Gary

  • 10-30-2008 06:50 AM In reply to

    Re: Add new row with VBScript

    Hi,

    Iam not understanding why you are using onAfterChange event still?. without using this event you can able to implement your functionality with the code given by jimmy. Can you please explain me clearly why you are using the onAfterChange event.

    Chandrakanth/GGKTech
  • 10-30-2008 07:51 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add new row with VBScript

    Hi

    The reason for using OnAfterChange event is so that I can automate the insertion of a new row after the user input, rather than have a button.

    Gary

  • 10-30-2008 11:12 PM In reply to

    Re: Add new row with VBScript

    Hi,

    Please follow the below code lines in your OnAfterChange Event. Hope it helps you.

    Dim rowAdded ' as Boolean

    rowAdded = false

    Sub msoxd_my_group2_OnAfterChange(eventObj)

    If eventObj.IsUndoRedo or rowAdded Then

                    Exit Sub

    End If

    rowAdded = true

    ‘Add the table row over here

    rowAdded = false

    End Sub

    Chandrakanth/GGKTech
  • 11-02-2008 07:20 AM In reply to

    Re: Add new row with VBScript

    Under what conditions/after what action do you want to add a new row to the table?  Surely you don't want to add a new row every time someone makes any change within the table.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-03-2008 01:09 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add new row with VBScript

    Thanks Chandrakanth

    Just what I needed

    Gary

  • 11-03-2008 01:12 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add new row with VBScript

    Jimmy

    The new row will be added when the user reaches the 255 character limit on the text box. This is to get around the limitations on the AccessDB it is submitted to.

    Thanks

    Gary

  • 11-03-2008 02:25 AM In reply to

    Re: Add new row with VBScript

    Hi, Please follow the below code lines in your OnAfterChange Event. Hope it helps you.Dim rowAdded ' as BooleanrowAdded = falseSub msoxd_my_group2_OnAfterChange(eventObj)If eventObj.IsUndoRedo or rowAdded or eventObj.Operation <> "Insert" ThenExit SubEnd Ifif eventObj.Source.parentNode.nodeName = "my:field2" then 'specify the field name in which you check the length if Len(eventObj.Source.parentNode.text) > 255 ThenrowAdded = true‘Add the table row over hererowAdded = falseend ifend if

    End Sub

    Chandrakanth/GGKTech
  • 11-03-2008 02:49 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add new row with VBScript

    I had already written the code to carry out this part of the operation, but this is a much tidier solution.

    Thanks again

    Gary

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