Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Mar 2003
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    copying number to text field and attach zeroes (Access 2k)

    does anyone know how I can add zeroes in front of a number? for eg i have a number field which I want to stoare as a text field (different field) but before storing it as a text field I want to attach 000 in front of that number so that the number 5 will be stored 0005.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: copying number to text field and attach zeroes (Access 2k)

    You can create a calculated column in a query. If you want to prefix ALL values with 3 zeros:

    FieldWith3Zeros: "000" & [FieldName]

    or if you want to use leading zeros so that all values are length 4:

    FieldWithLength4: Format([FieldName],"0000")

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: copying number to text field and attach zeroes (Access 2k)

    try something like this:

    Dim lenOfField as long

    lenOfField = len(yourField)
    Select Case lenOfField
    Case 1
    yourTextField = "000" & yourField

    Case 2
    yourTextField = "00" & yourField

    Case 3
    yourTextField = "0" & yourField

    Case else
    yourTextField = yourField

    End Select
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  4. #4
    Lounger
    Join Date
    Mar 2003
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: copying number to text field and attach zeroes (Access 2k)

    Thank you. Did not realize it was so simple!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •