Best way to return next primary key value

kleky

Just gettin' by..
Local time
Today, 10:01
Joined
Apr 11, 2006
Messages
43
Just trying to think what is the best/cleanest way to return the next primary key value which is in the format yyyy-###

These are case files for the current year, ### being 3 digit number incremented by one for each new case.

I could use a function that finds the last one, checks the date, increments by one and returns it, but maybe I could use a public property or a class? I'm keen to use classes more to help code maintenance.

With a class then: would i create a PrimaryKey variable of the class type/object, so when I need a new key I would just type PrimaryKey.NewKey, for example?

Hope that's clear...thanks for your help.

Ian
 
I would be using Autonumber as the Primary Key because that won't fail.

Then use another field for what you described.
 
Not sure why you need a class unless you have multiple primary keys with thhe same format. I would just use a public function in a module along the following lines

Public function NextPK(YearID as Integer) as String

...get max number for YearID
... add 1
... assign to NextPK

End if
 
Yes you're right, I think I'm just looking for ways to create a class so I can practice :)

Indeed, auto-number shall be used but must be in conjunction with this one too.
 
Have fun. I hope you learn what you want. Post back if you have problems.
 
Yes you're right, I think I'm just looking for ways to create a class so I can practice :)

Indeed, auto-number shall be used but must be in conjunction with this one too.

I am just reviewing a few posts. Did I read that you intend to combine the AutoNumber with this newly created field.

If so I do advise against it. Just use the AutoNumber as your primary key on its own.

This may raise some issues with you. If so please write back with your problem so we can explore a little closer.
 

Users who are viewing this thread

Back
Top Bottom