Function GetNextBillNo local lcAlias, lnReprocess, lnBillNo lcAlias=select() && remeber alias lnReprocess=SET('REPROCESS()') && remember value SET REPROCESS TO 1 && Retry evey one second SELECT 0 && find an available work area USE Billings order BillNo again && BillNo is an index tag on BillNo DO WHILE .T. GO BOTTOM && this record holds the highest number lnBillNo=billings.BillNo APPEND BLANK IF !RLOCK() && Someone else is doing exactly the same, so he comes first WAIT 'Someone else is billing, you must wait!' WINDOW NOWAIT LOOP && wait a second and try again ENDIF REPLACE Billno with lnBillno + 1 lnBillNo=billings.BillNo && lnBillNo is the next bill number EXIT ENDDO USE && Close WAIT CLEAR && In case any Wait window is open SET REPROCESS TO lnReprocess && always restore SELECT (lcAlias) && always restore RETURN lnBillNo4. Now you have the bill number, and can continue the process