Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto-incrementing a number field
Message
 
To
22/12/1998 12:31:25
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00168371
Message ID:
00169710
Views:
19
>>>>>>>Sorry Dan, must have hit the enter kit by accident on my last response.
>>>>>>>
>>>>>>>Any way, here is my suggestion:
>>>>>>>
>>>>>>>In your form init method:
>>>>>>>
>>>>>>>SELECT ;
>>>>>>>MAX(id_field) ;
>>>>>>>FROM table ;
>>>>>>>INTO ARRAY aHighestID
>>>>>>>
>>>>>>>IF _TALLY > 0
>>>>>>> THISFORM.object.value = aHighestID[1] + 1
>>>>>>>ELSE && No records on the table
>>>>>>> THISFORM.object.value = 1
>>>>>>>ENDIF
>>>>>>>
>>>>>>>This should do it for you.
>>>>>>>
>>>>>>>Good luck
>>>>>>
>>>>>>Many thanks Juan to you and others who helped me with this...
>>>>>>although there were many very good syggestions, your example sure helped me to finally resolve this issue!
>>>>>>
>>>>>>This is why I think the UT is the greatest thing since sliced bread!!
>>>>>>
>>>>>>Thanks to all,
>>>>>>Dan
>>>>>
>>>>>Dan, I'm sorry to interrupt here, but this way is highly suspicious in multi-user environment.
>>>>
>>>>I agree 100% with you Edward, however, this is one is those rare instances where this short and simole functions will work since it is NOT going to be used in a multi-user environment, should work fine.
>>>>
>>>>Any other app I would normally have used something like UniqueId()....
>>>>
>>>>Dan
>>>
>>>I see. Anyway, you don't need in SELECT here. You can just:
>>>Select MyTable
>>>Set Order To Tag ID
>>>GO BOTTOM
>>>nNewid=MyTable.Id+1
>>
>>I thought of useing something like above, but i wasnt sure if it would pick up any deleted records before the table had been packed and thus show a false number that didnt represent the actual number of records in the table.
>>I havent tried your code yet, but would this be the case?
>>
>>Dan
>
>If SET DELETED ON then GO BOTTOM will pickup the last non-deleted record in index sequence, and SET DELETED OFF will allow to pick up the last record regardless deleted status, i.e. you have a choice depending on what you want to achieve.

Sounds logical. Many thanks Ed!
Dan Gilliland
ICQ# 15695715


"Man is still the most extraordinary computer of all."
John F. Kennedy (1917-1963)
Previous
Reply
Map
View

Click here to load this message in the networking platform