Results 1 to 11 of 11
  1. #1
    thetcrew004 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    3

    Limited number of characters in a table

    I have a table that allows 6 characters (text) in the field, and I want all 6 characters need to be filled. For example: If a user puts in less than 6 characters (12345 or 9999), I want zeroes to be automatically added in the front (012345 or 009999). Any suggestions as how I can set this in a table?



    Thank you in advance!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In the textbox Afterupdate event, pad the value....


    Code:
    sub txtBox_afterupdate()
    TxtBox=String(6-len(txtBox),"0")
    end sub

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You typically would want to do this on the Form level (users should NEVER have direct access to the tables - all manual data entry should be controlled through Forms).
    On your Form, you can use the BeforeUpdate event of the Form to check and pad the leading zeroes for that field.

    For example, the code might look something like this:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Dim curEntry As String
        curEntry = Me.FieldName
        If Len(curEntry) < 6 Then
            Me.FieldName = Right("000000" & curEntry, 6)
        End If
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Or: Me.textboxName = Format(Me.textboxName, "000000")

    Be sure to set the field length in table design.

    Might also want to set Validation Rule to make sure user doesn't enter more than 6 digits and no alpha.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    thetcrew004 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    3
    Thanks for the suggestion, but I want to put this in the table. Any thoughts that I can do that.

  7. #7
    thetcrew004 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    3
    Quote Originally Posted by orange View Post
    Is part of the criteria --no alpha, no special characters --ONLY NUMERIC 0-9?


    That's correct. Just number only (0-9)

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Thanks for the suggestion, but I want to put this in the table. Any thoughts that I can do that.
    You cannot place VBA on a table.

    And users should NEVER be accessing or entering data directly into Tables.
    They should be going in through Forms, where you can set all sort of rules and validations like these.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in a table you could store as a number and format it using the format property - you would use 000000

  11. #11
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    in a table you could store as a number and format it using the format property - you would use 000000
    Just be aware that custom formatting a number does not change the value, only the appearance.
    So, if you enter a value like 123, it will be displayed as "000123", but its value will still be 123 and its length will be 3, not 6.

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

Similar Threads

  1. Replies: 1
    Last Post: 02-11-2015, 07:45 AM
  2. Replies: 1
    Last Post: 11-26-2013, 01:41 AM
  3. Limited characters in a memo field
    By Robbyp2001 in forum Forms
    Replies: 11
    Last Post: 11-24-2011, 07:04 AM
  4. MDB database field limited to 64 or 255 characters
    By galapogos in forum Programming
    Replies: 1
    Last Post: 04-06-2010, 10:22 AM
  5. Strings limited to 255 characters
    By ocordero in forum Programming
    Replies: 4
    Last Post: 08-09-2006, 09:13 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