By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

how to customize ID Number.

P: 14
How do I customize an ID as primary key to be anything other than numbers. For example what if I wanted to create an ID based on the last three letters of a last name and the extension number.

Thanks
Sep 14 '08 #1
Share this Question
Share on Google+
2 Replies


missinglinq
Expert 2.5K+
P: 3,532
For example what if I wanted to create an ID based on the last three letters of a last name and the extension number.
This is assuming that "extension" is a field in your table. In the code module of your form:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Extension_AfterUpdate()
  2.  If Not IsNull(Me.LastName) Then Me.IDNumber = Right(Me.LastName, 3) & Me.Extention
  3. End Sub
  4.  
  5. Private Sub LastName_AfterUpdate()
  6.  If Not IsNull(Me.Extension) Then Me.IDNumber = Right(Me.LastName, 3) & Me.Extension
  7. End Sub 
This is kind of an unusual way to do this. Most schemes of this sort use the first three letters of a last name together with a number. Which would be
Expand|Select|Wrap|Line Numbers
  1. Private Sub Extension_AfterUpdate()
  2.  If Not IsNull(Me.LastName) Then Me.IDNumber = Left(Me.LastName, 3) & Me.Extention
  3. End Sub
  4.  
  5. Private Sub LastName_AfterUpdate()
  6.  If Not IsNull(Me.Extension) Then Me.IDNumber = Left(Me.LastName, 3) & Me.Extension
  7. End Sub 
Linq ;0)>
Sep 14 '08 #2

NeoPa
Expert Mod 15k+
P: 31,342
The question isn't very clear, and Linq's answer could well be all you need. However, it is also possible to design a table where these elements are stored separately in two fields, but the Primary Key is made up of both fields. A Composite Index.

In Design mode simpy select all the required fields and click on the Primary Index button.

Even in this case, the AfterUpdate technique could be used if the partial name is required to be garnered from the contents of another field.
Sep 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.