I'm using the following code since some years, and it works very fine for me, perhaps it helps you. "Id" is a text field I use in every table. This function is called after every "append blank" statement.
*--- Automated id-counter 06.09.00 GN
*--- 20.11.2001 len for Id...