Custom Number Format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • UAlbanyMBA
    New Member
    • Nov 2006
    • 31

    Custom Number Format

    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
  • southoz
    New Member
    • Sep 2006
    • 24

    #2
    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

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      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.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Originally posted by NeoPa
        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

        Comment

        Working...