You could create a new table, and add a field for each criteria, and also a field for the last used value with this combo of criterias…
Put all criteria-fields in the primary key…
Then…
IF NewRec.GET(Crit1,Crit2,Crit3) THEN BEGIN
NewRec.LastUsedField := INCSTR(NewRec.LastUsedField);
NewRec.MODIFY;
END ELSE BEGIN
… insert the record with the needed value in LastUsedField
END;
CodeToUse := Crit1 + ‘-’ + Crit2 + ‘-’ + Crit3 + ‘-’ + NewRec.LastUsedField;
I was under the impression (from your own post earlier) that you wanted the final no. to have a given format (0001), and therefore concluded that you used datatype Code…
What I would do is create standard NAV numbering series for all combinations, and develop logic to select the right one, and from there let the standard numbering series take care of the numbers.