Expand my Community achievements bar.

Calculate Row Number - Auto Increment

Avatar

Former Community Member
I think I know what I want to do, I just don't know how to do it.



I have a form which has rows that can be added or deleted as the user requires. The first column in the row is a control number which has some static text and a number starting at 001 that I want to add to or subtract from based on the users action of clicking on the add or delete button.



The way I figured this would work was to place the number 1 in a hidden field on the form and att 1 to it each time the add button was pressed and/or delete 1 each time the delete button was pressed. The numbers in the remaining rows would need to be recalculated each time to ensure they are sequentially correct..



Could anyone point me in the right direction on how to accomplish this?



Thanks in advance for your replies. E
2 Replies

Avatar

Former Community Member
Easier than that, use the "index" property in the calculate event of the field you want to number:



$ = (concat("some_static_text", (Table1.Row1.index + 1)))



Also regarding the hidden field, luckily this case has a property you can use already. But if you need to maintain a counter outside of your table, use a variable instead of a hidden field.



Either add "var myVariable = null" to the initialize event of the table's subform (for a local variable) or else create a global variable in the form's properties: File > Form Properties > Variables tab.



Either way, you can pass things to and from the variable for use in your scripts.