# LastRepNumber ( repeatingField ; maxRepeat )

Returns the number of the last not empty repetition

Average rating: 3.9 (44 votes) Log in to vote

Daniele Raybaudi - Show more from this author
ACI http://www.aci.it |

Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns the number of the last not empty repetition, much like Last(repeatingField) returns its contents.

Can be used with both 7 and 8 version of FileMaker, but is most useful with 8, where fields can be reached specifying the repetition number by a calculation.

For example, to set the next empty repetition to "whatYouWant" you can use:

Set Field [repeatingField [LastRepNumber ( repeatingField ; 10 ) +1];"whatYouWant"]

(where repeatingField has 10 rep).

This function comes in hand also if you want to clear all repetitions.

A simple loop:

Loop

Exit Loop if [LastRepNumber ( repeatingField ; 10 ) = ""]

Set Field [repeatingField [LastRepNumber ( repeatingField ; 10 )];""]

End Loop

## Comments

Jim, NY Mar 20, 2014 |
||

Does not work if the repeatingField is referencing another repeatingField that is a calculation. This recursive function will return an incorrect number (always blank), since during the recursion, the repeatingField has not yet caluclated the result from the other repeatingField. Only works with repeatingField that are not based on other calculations. |
||

Bob, WA Jul 5, 2019 |
||

Using the Loop example to clear all repetitions does not work if it's a number field and any repetition has zero as the value. It doesn't clear the zero and doesn't exit the loop. Am I doing something wrong? | ||

Bob, WA Jul 9, 2019 |
||

OK, I figured this out. If the last non empty repetition in a number field is 0 (zero) or an invalid entry, the result is maxReapeat instead of the repetition number with the data. The following fixes it and also works if there’s an invalid entry in a date field. It also fixes the loop example to clear all repetitions. Case ( IsEmpty ( Last ( repeatingField ) ) ; "" ; GetAsText ( Last ( repeatingField ) ) = GetRepetition ( repeatingField ; maxRepeat ) ; maxRepeat ; LastRepNumber ( repeatingField ; maxRepeat - 1) ) |
||

Bob, WA Jul 9, 2019 |
||

OK, I figured this out. If the last non empty repetition in a number field is 0 (zero) or an invalid entry, the result is maxReapeat instead of the repetition number with the data. The following fixes it and also works if there’s an invalid entry in a date field. It also fixes the loop example to clear all repetitions. Case ( IsEmpty ( Last ( repeatingField ) ) ; "" ; GetAsText ( Last ( repeatingField ) ) = GetRepetition ( repeatingField ; maxRepeat ) ; maxRepeat ; LastRepNumber ( repeatingField ; maxRepeat - 1) ) |
||

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.