FUNCTION GetNextOrderNumber LOCAL lnNextOrderNum AS Integer SELECT orderlist LOCATE FOR DELETED() IF FOUND() RECALL lnNextOrderNum = orderlist.ordernum ELSE GOTO BOTTOM lnNextOrderNum = orderlist.ordernum + 1 INSERT INTO orderlist (ordernum) VALUES lnNextOrderNum ENDIF RETURN lnNextOrderNum ENDFUNCThis now gives you a order number that will be unique. If the user cancels the order request, then delete the record from the orderlist table:
FUNCTION DeleteOrderNumber LPARAMETERS pnOrderNum DELETE FROM orderlist WHERE ordernum = pnOrderNum ENDFUNCIf the user commits the order, then the order number is what is used in your order header table and order items table as the key.