Board index » delphi » Need code to assign value to primary key field

Need code to assign value to primary key field

Reference a table named Brands with fields named Code and Make. The fields
'Code' and 'Make' are type Tstring fields where 'Code' is a primary key
field containing six characters. In the OnNewRecord event, I want to grab
the first four characters of BrandsMake.value then add the character string
'0i' (where i represents values from 1 to 9) to the right end of the string.
For example, if two records contain values 'Heil' and 'Heil Quaker' in the
field 'Make', then the corresponding values assigned to the field 'Code'
should be 'Heil01' and 'Heil02'. Thank you ahead of time.

Marty Potokar

 

Re:Need code to assign value to primary key field


How do you propose to find the number? You cannot do so by counting
the records because a record could have been deleted and the existing
numbers might be Heil01 and Heil03. In that case, I assume the next
record should be Heil04.

It would be easier if you stored the first four characters in one
field and the number in another field. Then you could create an index
on the two fields and do a SetRange on the first to get the existing
records in numerical order. Looking at the last record would tell you
the highest existing number.

All of this assumes you are using Paradox tables. It really is easier
if you tell us what database you are using.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Re:Need code to assign value to primary key field


Bill,

I am using DBISAM.

Quote
"Bill Todd" <n...@no.com> wrote in message

news:vvdvsvcujlsvjt70skji6c41hm2509nppr@4ax.com...
Quote
> How do you propose to find the number? You cannot do so by counting
> the records because a record could have been deleted and the existing
> numbers might be Heil01 and Heil03. In that case, I assume the next
> record should be Heil04.

> It would be easier if you stored the first four characters in one
> field and the number in another field. Then you could create an index
> on the two fields and do a SetRange on the first to get the existing
> records in numerical order. Looking at the last record would tell you
> the highest existing number.

> All of this assumes you are using Paradox tables. It really is easier
> if you tell us what database you are using.

> --
> Bill (TeamB)
> (TeamB cannot respond to questions received via email)

Re:Need code to assign value to primary key field


I have never used DBISAM but my understanding is that its table
component supports SetRange so the information in my last message
should apply.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Other Threads