Database servers often have options like sequences, autoincremental fields, or something similar. Perhaps you can consider using the capabilities of the server, in SQL Server?
Even newer versions of VFP now have auto-incremental fields, but in this case, I would prefer to use my old SerialNumber() routine (similar to the one you have).
By the way, I suggest you write your VFP code within PRE tags. This will preserve spaces and tabs, and avoid word wrap. Note how in the following example, spaces are maintained. Click on "Reply" to see how I wrote the following:
with This
if SomeCondition
.SomeMethod()
endif
endwith
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)