Results 1 to 6 of 6
  1. #1
    nd0911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    31

    VBA Update query table with leading zero's

    Hello there,

    With VBA I want to query a table that have a field with "text numbers", the query purpose is to add a leading zero's to the "text numbers" field from the left side for maximum of 8 digit's.



    for example: 1234 will be 00001234, 123456 will be 00123456

    Those value's should change in the table itself in the "text numbers" field, so the the "text numbers" field he is the source and he is the target.

    Is it possible ?

    TNX !!

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349

    You can create an update query to update the column to: String(8 - Len([YourFieldName],"0") & [YourFieldName]

    Any time you do something like this to a table, make a backup first in case it doesn't work out as planned.

    Although I am curious why you want to "format" the value in the table. The table should hold the value. Formatting is done when you want to display the value in a form or print it on a report.

  3. #3
    nd0911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    31
    Can you please show me the all VBA line of code for it ?

    Thank you very much !

  4. #4
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    You don't need to do it in VBA. Just create an Update Query in the Query Builder.

    UPDATE tblYourTableName Set [YourFieldName] = String(8 - Len([YourFieldName],"0") & [YourFieldName]

    Do remember to backup before doing this, just in case...

  5. #5
    nd0911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    31
    Thank you very much it works !!

  6. #6
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Cool. Happy to assist.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2015, 07:18 PM
  2. Replies: 1
    Last Post: 03-17-2015, 05:27 PM
  3. Replies: 9
    Last Post: 12-05-2013, 11:48 AM
  4. Replies: 1
    Last Post: 02-08-2012, 04:50 PM
  5. Replies: 2
    Last Post: 11-04-2011, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums