Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

an easy incrementing primary key

Status
Not open for further replies.

fneily

Instructor
Apr 5, 2002
2,538
US
Let's say you want to create your own autoincrementing primary key. And it's in the form of abc#### - abc001, abc002, etc. What do you all think of this? Create a table with a field say Increment. This will be set to automatically increment. Then create a field for your primary key, eg. customer id. Create an input form. In design view, bring up the property sheet for the text box Increment. In the Default value box, type =DMAX("[Increment]","Tablename")+1 Tablename is the name of your table. Then hide this control by changing the Visible box to NO. In the Format box, type 000 (zeros) or how many places you want.
NOTE:I got the above function statement from somewhere in this thread.
Click on the text box for customer id so the property sheet reflects this control. In this control's Default value box, type ="abc"&Format([Incremant],"000").
Set Tab Stop to NO for both controls.
Now when you go to a new record, the Increment goes up by 1 and the result is concatenated to whatever prefix you want in your primary key.
Any critics are welcomed.
Neil
 
This process was "cleaned up" under the Access Forms thread.
Neil
 
fneily,

What is your purpose for creating your own incrementing field in this manner? Why not simply allow Access to create the unique id with the autonumber field? Then use a query with a concatenation function in order to display the data as desired later.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top