All the data comes from our Finance department. I have no idea how they arrive at the numbers but the percentage is somehow tied to the department. So realistically, the same value could exist for more than one department. I believe they will just manually update the file quarterly.
Hi JR,
Sorry for the delay as I was unexpectedly out of the office.
See if these steps work in your scenario:
- Modify your sample XML file to the following:
<?xml version = "1.0" ?>
<Rates>
<Rate>
<Display>Item 1</Display>
<Value>6</Value>
<myKey>6-Item 1</myKey>
</Rate>
<Rate>
<Display>Item 2</Display>
<Value>8</Value>
<myKey>8-Item 2</myKey>
</Rate>
<Rate>
<Display>Item 3</Display>
<Value>6</Value>
<myKey>6-Item 3</myKey>
</Rate>
</Rates>
- Create a new, blank InfoPath solution
- Add a "Receive" data connection to the above referenced XML file named:
TestXML
- Add a drop-down list and text box to the form
- Right-click on the drop-down box and choose Properties
- Set the data connection of this control to: TestXML
- Click the Select XPath button next to Entries, select "Rate" and click OK
- Click the button next to Value Field, select myKey and click OK
- You can leave Display name as: Display
- Click OK to close this Property window
- Right-click on the text box control and choose Properties
- Click the "fx" button next to the Value field for the Default Value
- Click Insert Field or Group
- From the Data Source box choose: TestXML
- Drill down, highlight Value (under Rate) and click the Filter Data button
- Click Add
- From the first box, choose: myKey
- From the second box, choose: is equal to
- In the last box, choose: Select a field or group
- From the Data source box, choose: Main, highlight your drop-down list box
field and click OK
- Click OK 3 times to get back to the Insert Formula window - you should
basically see this: Value[myKey = field1]
- Modify this now to: Value[myKey = field1] * 10 (just to do some
mathematical function)
- Click OK 2 times to get back to your form
- Preview and test - you should be able to select any of the items in the
list and the result in the text box should change appropriately
Let me know if this works for you!!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
JR - 01 Sep 2005 15:51 GMT
Hi Scott;
That's working beautifully; it's fixed all the problems with the text box values changing; but it's cropped up one other slight issue. Until someone actually selects a value (and this is an optional field); the values calculated based on the DDL selection are all non-numbers (NaN).
This fouls up some of the other totals when this occurs. Is there a way I can force NaN values to be zero in the calculated fields if nothing is selected in the DDL or set a default selection from the DDL?
I've also noticed a blank entry in the DDL, is that by design?
> Hi JR,
>
[quoted text clipped - 134 lines]
> \par
> \par }
Scott L. Heim [MSFT] - 01 Sep 2005 18:40 GMT
JR,
(** NOTE: You may want to read all of this before taking any action! <G>)
In that case, you can move the expression from the "Default Value" field
for the text box and use it as a "Rule" on your drop-down box:
- Right-click on your text box and choose Properties
- Click the "fx" button next to Value and "cut" the expression from the box
- Right-click on the drop-down box and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box choose: Set a field's value
- Click the button next to Field, highlight your text box field and click OK
- Click the button next to Value and paste the expression you "cut" from
above
- Test!
In regard to the blank row, if you can use a default value from your XML
file then you can use these steps:
- Display the Data Source Task Pane
- Select Main from the Data Source drop-down
- Right-click on the node that represents your drop-down list and choose
Properties
- Set a default value (as an example, I used: 6-Item 1)
Now, the problem with using this option along with moving the expression to
a Rule is that the text box will not get populated with the value until
after a selection is made. So....after all of this <G> what I would do is
leave the expression as the "Default Value" for the text box and set one of
your options from the XML file as the default selection.
Now that I have totally confused you, let me know if this is a viable
option!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights