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

How to view the YEAR in Auto Number Data type?

P: 1
Hi All,

I have a table that use an Auto Number (Data type) as my primary key. I want my field to be look like this.

WJ-2012-00001 ---> first entry.

"WJ" , "-" and "2012" ---> are all constant.

The last Five Digit is the Auto Number.

Please help me to solve my problem.
Jan 12 '12 #1
Share this Question
Share on Google+
3 Replies

P: 332
IF "WJ" , "-" and "2012" ---> are all constant, then what is the point of even considering storing this and waste space? Will 2012 at one point be 2013?

Is WJ and 2012 recorded is some other field?

If that is really what you want, you can specify the format in the table design for the given field.
Jan 12 '12 #2

Expert Mod 15k+
P: 31,487
Mario is right. You need to ask your question properly, making it clear, before we can provide an answer that matches your question. Anything offered at this point is in danger of being on the wrong lines as we can't know what they are until you tell us. What is WJ? And what is 2012? Please explain clearly.
Jan 12 '12 #3

P: 144
This is a "composite" key. The autonumber increments, the other 1 or 2 parts of the key are constant. To put it all in one field you can't use strings (they don't increment too well). You can put the info into 2 or three fields and create a composite key, setting the default value to WJ- and 2012- and then keeping your autonumber field free to increment. You would still have to deal with the extra zeros.

I understand why you want something like this to handle unknown future conditions. I'd use three fields, like what was said, for changing the constant values (based on year change or what-not). All of this looks like a progamming issue on the input with some concatenation going on, and some math; but I know once that is coded, you can make the properties of all three fields set to primary "composite" key, so that they react together with other queries. Also, you can designate a field as "primary" without using autonumber--you'd just have to be prepared to trap the error on input for dups. Hope this helps...
Jan 15 '12 #4

Post your reply

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