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

Custom Number Format

P: 31
I am working on a project using Access 2003. I am using the Autonumber as an ID generator, and I want it to be random. I want to format it to 5 digits, but I can't get it to work. I have made all the numbers positive, but the desired size doesn't work. How can I make the length of the autonumber 5 digits? If the answer is to use VBA coding, please be specific, because the team members on this project are beginners in linking VBA to access. Thank you.

UAlbanyMBA
Nov 10 '06 #1
Share this Question
Share on Google+
3 Replies


southoz
P: 24
Good ay UAlbanyMBA

well straight from the manual & vb help files
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

have fun
southoz
Nov 10 '06 #2

NeoPa
Expert Mod 15k+
P: 31,492
AutoNumber is specifically for generating IDs in records, generally for use as a PK.
SouthOz's answer provides you with a way to generate random numbers to fit your requirement.
What do you mean about storing as 5 didgits?
Numbers are not stored as any specific number of digits - that is only used for display.
To show a number as a five digit string use Format(number, "00000") (unless this is within a SQL string when the format string would be written as '00000' instead.
Nov 11 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
AutoNumber is specifically for generating IDs in records, generally for use as a PK.
SouthOz's answer provides you with a way to generate random numbers to fit your requirement.
What do you mean about storing as 5 didgits?
Numbers are not stored as any specific number of digits - that is only used for display.
To show a number as a five digit string use Format(number, "00000") (unless this is within a SQL string when the format string would be written as '00000' instead.
And if you want to do this at table design level simply put five 0's in the Format property of the field in design view.

00000

No quotes required
Nov 12 '06 #4

Post your reply

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