Solved

Infopath Custom Code Issue

Posted on 2013-10-29
7
356 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now