Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Nadeem Shah
  Where is Nadeem Shah?
 Rawalpindi
 Pakistan
 Nadeem Shah
 To: Marcia Akins
  Where is Marcia Akins?
 Akorn
 Ohio - United States
 Marcia Akins
 Tags
Subject: RE: Auto increment field
Thread ID: 143180 Message ID: 143209 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Sunday, August 26, 2007 4:22:09 AM         
   


> I mostly used append blank command. But some times i dont want to save records but auto increment field incremente. So in that case(dont save record) i just want to back my prevous auto increment value
>
> If you need a sequential number with no gaps, do not use an autoincrememnting integer. Use an integer field that you can incrememnt yourself in code like this when the record is saved:
>
>
> Function newid( tcTable )
>   Local lcTable, lnNextVal, lnOldRepro
>   *** Check Param and convert to upper case
>   If Empty(tcTable) Or Vartype( tcTable ) # "C"
>     Assert .F. Message 'This is another Brain Dead Programmer Error'+Chr(13)+'You MUST specify an alias for the NewID Function'
>     Return 0
>   Endif
>   lcTable = Upper(Alltrim( tcTable ))
>   *** Save Settings and Open System table if not already open
>   lnOldRepro = Set('REPROCESS')
>   If ! Used('System')
>     Use System In 0
>     If Txnlevel() < 1
>       *** Make sure that the table is not buffered
>       CursorSetProp( 'Buffering', 1, 'System' )
>     Endif
>   Endif
>   *** Now find the required table
>   If Seek( lcTable, 'System', 'cTable' )
>     *** Found the required table
>     *** Get a Lock on System
>     Set Reprocess To Automatic
>     If Rlock( 'System' )
>       *** Get next value and update System table
>       lnNextVal = System.iLastKey + 1
>       Replace iLastKey With lnNextVal In System
>       Unlock In System
>     Else
>       lnNextVal = 0
>     Endif
>   Else
>     If Version(2) # 0
>       *** In Dev Mode ONLY
>       Assert .F. Message 'No Entry for ' + lcTable + ' - Adding One'
>       *** Not Found!
>       lnNextVal = 1
>       Insert Into System (cTable, iLastKey) Values ( lcTable, lnNextVal )
>     Else
>       *** At Run Time - just cause an error
>       lnRetVal = 0
>     Endif
>   Endif
>   *** Return New ID
>   Set Reprocess To (lnOldRepro)
>   Return lnNextVal
> Endfunc
> 

>
>
>
> Regards,
> Marcia G. Akins
> Tightline Computers, Inc.


Thanks Marcia. My rating for you. Will this routine work well in private data sessions too, mean 3 or 4 persons at a time add something then ?


Nadeem Iqbal

ENTIRE THREAD

Auto increment field Posted by Syed Nadeem Iqbal @ 8/25/2007 7:14:13 PM
RE: Auto increment field Posted by Borislav Borissov @ 8/25/2007 7:26:32 PM
RE: Auto increment field Posted by Ken Murphy @ 8/25/2007 7:40:03 PM
RE: Auto increment field Posted by Syed Nadeem Iqbal @ 8/26/2007 4:24:49 AM
RE: Auto increment field Posted by Syed Nadeem Iqbal @ 8/25/2007 8:30:17 PM
RE: Auto increment field Posted by Marcia Akins @ 8/25/2007 9:12:34 PM
RE: Auto increment field Posted by Syed Nadeem Iqbal @ 8/26/2007 4:22:09 AM
RE: Auto increment field Posted by Andy Kramek @ 8/27/2007 1:08:07 PM
RE: Auto increment field Posted by Thomas Bähr @ 8/27/2007 5:48:07 PM
RE: Auto increment field Posted by Marcia Akins @ 8/28/2007 3:14:23 PM
RE: Auto increment field Posted by Syed Nadeem Iqbal @ 8/28/2007 6:39:17 PM
RE: Auto increment field Posted by Ken Murphy @ 8/26/2007 3:04:29 PM