Solved

Infopath Custom Code Issue

Posted on 2013-10-29
7
366 Views
Last Modified: 2013-11-04
I am using a loop to iterate through my Main Nodes in a repeating table in Infopath 2010.
When I get to the field that I am using a calculated value as the default I am getting an error, "Object reference not set to an object",

Here is my code:

 'Count the amount of Field nodes
            Dim iter As XPathNodeIterator = root.Select("/my:myFields/my:ImportFields/my:Fields", NamespaceManager)
            Dim FieldsCount As Integer = iter.Count
            Dim sb As New System.Text.StringBuilder()

            If FieldsCount > 0 Then
                'Check mappings.
                While iter.MoveNext
                    If iter.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value = "" Or iter.Current.SelectSingleNode("my:MappedField", NamespaceManager).Value = "None" Then
                        sb.Append("Row " & iter.Current.SelectSingleNode("my:RowNo", NamespaceManager).Value & " is not mapped." & System.Environment.NewLine)
                    End If
                End While

Open in new window

0
Comment
Question by:redeux-tech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 28

Expert Comment

by:clayfox
ID: 39609404
You may have the recalculate check box on the default value. It may be looping trying to recalculate when you move through the field.
0
 
LVL 1

Author Comment

by:redeux-tech
ID: 39609569
I already tried removing the check box and it is still not working.
0
 
LVL 28

Expert Comment

by:clayfox
ID: 39609577
Maybe try removing the default value and just use a rule or code at load that sets the value.

Might allow you to get around the issue.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 1

Author Comment

by:redeux-tech
ID: 39609582
This what the error looks like in progress....
0
 
LVL 1

Author Comment

by:redeux-tech
ID: 39609686
I have the datasource for this field set to position().  Is that what is causing this to not return a value?
0
 
LVL 1

Accepted Solution

by:
redeux-tech earned 0 total points
ID: 39612074
Ok, I figured out my own problem here.  

1 -  I had to fix the field so that it's datasource was no longer position()

2-  I had to map the calculated value field so that it was mapped to the field on the Main datasource so that the value was saved.

3 -  I set the field's default value to count(preceding-sibling::*/RowNo) + 1 and it doesn't matter that refresh value when formula is calculated is checked.

4 - I had to make sure that my code that inserted new rows into the repeating table (XMLWriter) was inserting the nodes in the correct order as they appeared in the Main datasource.
0
 
LVL 1

Author Closing Comment

by:redeux-tech
ID: 39621080
I solved my own issue and I outlined the solution in this comment.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question