Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primary Key
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00532997
Message ID:
00534766
Views:
13
Hi Leroy,

Check Craig Bernston site (he participated in this thread). He has a program to generate PK there. The code, you posted, has few flaws, so I'd recommend you to check it.

>>
>I have problem with primary key, when I delete record and enter new record with same value in primary field error come value already exist. If any body has a solution, please reply
>
>Hi Javed!!!
>I had that very same problem last week.
>If you want to keep the deleted records for the history or something try this method.
>
>
>FUNCTION GET_PRIMARY_KEY
>LPARAMETER lcTable,lcFieldName,lcIndexOnExp
>LOCAL lnLastNum,lnNewNum
>
>SELECT &lcTable
>SKIP -1
>lnLastNum = &lcFieldName
>SKIP
>IF !USED('DATA\IDS') 	  && my table of ids
>	USE ('DATA\IDS') IN 0	
>ENDIF	
>SELECT IDS
>SET ORDER TO ID
>IF !SEEK(lnLastNum)   && if I don't find it in my table of ids
>	append blank
>	replace id with lnLastNum
>	replace iddescp with left(spellamt(lnLastNum),AT('And',spellamt(lnLastNum))-1)
>ENDIF
>lnNewNum = IDS.ID + 1
>SELECT IDS
>USE
>SELECT &lcTable   && the table i want the key in
>SET DELETED OFF
><b>DO WHILE SEEK(lnNewNum)  && check to see if that number is in there
>	lnNewNum = lnNewNum + 1
>ENDDO  && when it is not, pop out</b>
>SET DELETED ON
>RETURN lnNewNum
>ENDFUNC
>
>
>As much as I don't like the Do WHILE, This was the only way I could get it to work in my table. The Do While Statement might be what you need.
>
>HTH
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform