Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:08:45+00:00 2026-05-31T00:08:45+00:00

I have a text field in Microsoft Access which consists of only digits. I

  • 0

I have a text field in Microsoft Access which consists of only digits. I don’t know if these digits are preceded by blank characters or not.

What I want to do is if the field has ‘1’ I want to convert it to ‘0001’, if it has ’89’ then I want to convert it to ‘0089’, etc. Meaning I just want to make the field consistent in length of 4 characters and pad the number with the appropriate number of ‘0’s.

How do I do this? Can I use the calculated field approach?
I can convert the database to SQL if SQL has an easy way to do this.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:08:46+00:00Added an answer on May 31, 2026 at 12:08 am

    You can use the Format() function to transform the string of digits. Format() doesn’t care whether or not the digits are preceded by spaces.

    ? Format("89","0000")
    0089
    ? Format("    89","0000")
    0089
    

    If you want to display those field values with that format in a query:

    SELECT Format([YourTextField],"0000")
    FROM YourTable;
    

    If you want to change how they’re stored:

    UPDATE YourTable
    SET [YourTextField] = Format([YourTextField],"0000");
    

    Edit: @onedaywhen suggested a using CHECK CONSTAINT or Validation Rule to ensure your table only accepts valid data in the future. Here is a CHECK CONSTRAINT example:

    ALTER TABLE YourTable
    ADD CONSTRAINT four_digits_required
    CHECK (
        YourTextField LIKE '[0-9][0-9][0-9][0-9]'
        );
    

    You can run that statement from CurrentProject.Connection.Execute, which is an ADO object method. DDL statements with CHECK constraints can only be executed from ADO. So you could not execute that statement from CurrentDb.Execute, which is a DAO object method.

    Alternatively this should work for YourTextField’s Validation Rule property:

    LIKE "[0-9][0-9][0-9][0-9]"
    

    The Validation Rule approach would also allow you to use the Validation Text property to display a message to the user when submitted values are unacceptable:

    "4 digits required."
    

    In this situation the Validation Text approach is about the same as displaying the CHECK constraint name when that constraint is violated. However, if you wanted a more detailed message, the Validation Text could be a better choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a text field which I would like to bind to a
I have a text file which was created using some Microsoft reporting tool. The
I have two text fields which whatever user enters in first text field, it
For example: In my table I have text field with following text: The quick
I have a text field. If it has wrong values then it may show
i have a text field in Contact screen and the user need to enter
I have a text field that is near the bottom of the screen. When
I have a text field and am looking to have if be valid for
I have a text field that is a date, although sometimes it also has
I have a text field whose length I would like to limit at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.