Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting Primary Key with Deault Vaue
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00483683
Message ID:
00483716
Views:
9
>In my table I am setting the default value of the field for my primary key with an incremented value from a table that contains the listing of my tables (if that makes any sense). There is a field in that table that holds the last key for the table it corresponds to.
>
>My question is: how in my procedure to set the key do I know the name of the table I am inserting into to be able to pass it to the procedure. The procedure has to look up the table and increment the number then return it to me inside my field.
>
>I can't seem to find this information. I am sure it is probably something simple I am overlooking.
>
>Thanks for any help.

In your GetNextID routine you can have this code:
lparameter tcTable
if empty(tcTable) or vartype(tcTable)<>"C" && forgot to pass tcTable
  * well, we can assume, it's the name of the current alias table - it's not 100% safe, but better, than nothing
    local lcAlias
    lcAlias=alias()
    if empty(lcAlias) && this is too bad
        * messagebox()
       return .f.
    else
      tcTable=juststem(dbf(lcAlias))
    endif
endif
* proceed with the rest of the routine
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