Showing the Count
Question: I am trying to build an InfoPath form that has a bit of a strange requirement. I can’t quite figure out how I should do it and was hoping that you might be able to help? Basically, the requirements of the form require that we provide an ongoing count of the number of rows in a repeating table. So for example, if I have a table that has 10 rows in it, then there should be a display box that says 10. If they delete it then 9 and so on. I would think I could do something with an expression box – but can’t quite figure out what formula I might need? Any ideas would be much appreciated!
Answer: Actually, this is pretty easy to do and the expression box would be how I would do it.
Assuming that you have a data source that looks like the following:
You can then create a simple repeating table as shown here
Once this done you can go ahead and create an expression box. Keep in mind that this won’t store the number of entries in the data source. This will make it part of the view it is added to. You may need to add it to additional views within your form. Within the expression box use the “count” function of XSD.
count(my:Contacts/my:ContactName)
Now when the form is run, it will show the count of contact names that are entered in the form as shown below: