>FUNCTION GET_PRIMARY_KEY >LPARAMETER lcTable,lcFieldName,lcIndexOnExp >LOCAL lnLastNum,lnNewNum > >SELECT &lcTable >SKIP -1 >lnLastNum = &lcFieldName >SKIP >IF !USED('DATA\IDS') && my table of ids > USE ('DATA\IDS') IN 0 >ENDIF >SELECT IDS >SET ORDER TO ID >IF !SEEK(lnLastNum) && if I don't find it in my table of ids > append blank > replace id with lnLastNum > replace iddescp with left(spellamt(lnLastNum),AT('And',spellamt(lnLastNum))-1) >ENDIF >lnNewNum = IDS.ID + 1 >SELECT IDS >USE >SELECT &lcTable && the table i want the key in >SET DELETED OFF ><b>DO WHILE SEEK(lnNewNum) && check to see if that number is in there > lnNewNum = lnNewNum + 1 >ENDDO && when it is not, pop out</b> >SET DELETED ON >RETURN lnNewNum >ENDFUNC >>