Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although Steve's solution is very good, especially utilizing the database container and assigning rules, you are obviously stuck (somewhat) with your situation. If you are trying to add records and need to create your own auto-increment, you may have to do it by just a procedure call and assign it. This is just an example, but may help you out.</p> <pre><code>FUNCTION AddMyNewRecord() */ localized variable so you don't accidentally mangle some otherwise */ coincidental variable somewhere else. Preserve work area at start local lnSelect, llSaveOk, lnAttempts, lnNewPKID lnSelect = select() llSaveOk = .f. select YourAddressTable if NOT FLOCK() lnAttempts = 0 do while lnAttempts &lt; 10 AND NOT FLOCK() wait window "Attempting lock for address table..." timeout 1 enddo endif if NOT FLOCK() messagebox( "Unable to lock file to add next record primary key." ) else */ We have a lock, now try to detect both the highest and lowest */ EXISTING key for the table use in select( "C_TryNextKey" ) select MIN( YAT.PK ) as MinKey,; MAX( YAT.PK ) as MaxKey ; from ; YourAddressTable YAT; into ; cursor C_TryNextKey readwrite */ Determine if you need higher or lower key sequence if CriteriaForPositiveKey lnNewPKID = C_TryNextKey.MaxKey +1 else */ must be getting next LOWER sequence lnNewPKID = C_TryNextKey.MinKey -1 endif */ close temp cursor from getting respective high / low key use in select( "C_TryNextKey" ) */ NOW, we can add the new record Select YourAddressTable APPEND BLANK */ replace PK and all the other fields you need to do too Replace PK with lnNewPKID,; Address1 with lcSomeVariableYouHaveForAddress1,; Address2 with lcSomeVariableForAddress2,; AnyOtherFields with lcOtherFieldsToBeSet */ Unlock the address table UNLOCK */ set flag so we know it worked vs not. llSaveOk = .t. endif */ Return back where it started select( lnSelect ) */ Return if the save was ok or not. return llSaveOk endproc </code></pre> <p>This does not modify the existing database, nor table structure. It will however try to get a lock on the table before inserting your new record content. Then look at lowest and highest ID. You will have to analyze the data to find out why some have negative vs positive and update the condition I "place-holder" put in the code above. At the end, unlock the table.</p> <p>If this makes sense, great, if you need adjustments, let me know and I'll try to help guide you more.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload