Hello all
I have written some code for a form that will do some updates to a repeating table. The code is written in VBscript.
What happens is the when I add a Name in the field for POC and then ‘OnAfterChange#%92 would like that name updated in Contributor field also. This all works now. Problem I am having now is that went I add a second POC name, Contributor table has three records in the table.
Example
POC Joe Jones
Contributor Joe Jones
Next entry
POC Fred Smith
Contributor Joe Jones
Fred Smith
Fred Smith
Here is the Code I am using
sub msoxd_my_POC_Name_SingleName_OnAfterChange(eventObj)
Dim ObjPOCName
Dim iloop
iloop = 0
display("this is Iloop " & Cstr(iloop))
' Write code here to restore the global state.
If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If
Set ObjPOCName = XDocument.DOM.selectSingleNode("/my:Project/my:POC/my:Name/my:SingleName")
' A field change has occurred and the DOM is writable. Write code here to respond to the changes.
if iloop = 0 then
AddtoTable(ObjPOCName.text)
iloop = 1
end if
'Display("POC Name is " & ObjPOCName.text)
End Sub
Function Display(ByVal data)
XDocument.UI.Alert(data)
End Function
'=======
' The following function handler is created by Microsoft Office InfoPath.
' Do not modify the name of the function, or the name and number of arguments.
' This function is associated with the following field or group (XPath): /my:Project/my:Contributors/my:Contributor/my:Name/my:SingleName
' Note: Information in this comment is not updated after the function handler is created.
'=======
Sub msoxd_my_Contributor_Name_SingleName_OnAfterChange(eventObj)
' Write code here to restore the global state.
Dim ObjContName
Dim oSampleRow
Dim iSelectedIndex
If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If
' A field change has occurred and the DOM is writable. Write code here to respond to the changes.
'Set ObjContName = XDocument.DOM.selectSingleNode("/my:Project/my:Contributors/my:Contributor") '/my:Name/my:SingleName")
'Display("Inside COntributor Name Node Contributor Name is " & ObjContName.text)
'iSelectedIndex = XDocument.DOM.selectNodes("/my:Project/my:Contributors/my:Contributor").length 'GetSelectedPartsIndex("/my:Project/my:Contributors/my:Contributor") '/my:Name/my:SingleName")
'Display (iSelectedIndex)
End Sub
Sub AddtoTable(strValue)
Dim iSelectedIndex
Dim objSelectedNode
dim objNode
dim objNewRow
dim objSimpleRow
Set objNode = XDocument.DOM.selectNodes("/my:Project/my:Contributors/my:Contributor" )
Set objSimpleRow = objNode.nextNode()
Set objNewRow = objSimpleRow.cloneNode(true)
objNewRow.selectSingleNode("/my:Name/my:SingleName").text = strValue
'iSelectedIndex = XDocument.DOM.selectNodes("/my:Project/my:Contributors/my:Contributor").length 'GetSelectedPartsIndex("/my:Project/my:Contributors/my:Contributor") '/my:Name/my:SingleName")
XDocument.DOM.selectSingleNode("/my:Project/my:Contributors").appendChild(objNewRow)
'Display("The recond Number is " & Cstr(iSelectedIndex) & " The Record is " & XDocument.DOM.selectSingleNode( "/my:Project/my:Contributors/my:Contributor[" & Cstr(iSelectedIndex) & "]/my:Name/my:SingleName" ).text)
end sub
Thanks in advance for all your help
Jim