How do I get an incremental counter on the added subforms after pressing the "Add" button

kirstinp8449529 07-07-2017

I have a numeric field set up with default set to 1, when I press the  "Add" button a new version of the subform is added after.  My numbering is all messed up.  If I press the add button, the first subform becomes 2 and the added one stays 1.  When I press the add button on the second version of the subform, subform 1 becomes "3", subform 2 becomes "2" subform 1 becomes "1".  But if I press the add button on subform 1 again, subform 1 stays "2", subform 2 says "2" and subform 3 says "1"

My "Add" button coding is

_Subform.addInstance(1);

Subform.NumericField.rawValue =

parseInt(Subform.NumericField.rawValue) + 1;

My delete button coding is

Subform.removeInstance(_Subform.count-1);

It's set like this to always remove the "last" subform, but might be worthwhile to be set up to remove "that" instance of the subform but I don't know how to do that.  Can anyone help?

Mark Solution

Are these answers useful?
Help other community members by marking useful answers as accepted.

Accepted Solutions (0)

Answers (2)

Answers (2)

kirstinp8449529 07-07-2017

I've tried numerous scripts in the calculate event, nothing works there.

I don't understand what is meant by parent here either, I tried to put that coding into my delete buttons and it just deletes the first record, not the one it's on.

Sent from my iPhone

Magus069
MVP
07-07-2017

Hi there,

if you want to have the exact number of row your numeric field represents, you should use the calculate event instead of adding 1 each time you click add button. So in the calculate event of your numeric field, simply input the index value of the subform + 1...

You can also use the index to remove the instance of the subform of the delete button that have been clicked.

Ensure that specifying parent refers to the right parent as the subform in question.

Parent property only works if the buttons are inside the subform.