Results 1 to 5 of 5
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310

    Add zeros to the left using Input Mask

    Hi To all,


    I have a field in a table. The field size s three. If the user enters a one character for example, how can I build an input mask to allow leading zeros?
    Example:
    1 ---> 001
    k ---> 00k
    23 --> 023
    123 --> 123

    Khalil

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I'm not sure that can be done with an input mask. I think you would need some code the the Before Update event of a control on a form.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    On refection, the code would need to be in the AfterUpdate event of the control. Something like:
    Code:
    Select Case Len(Me.ActiveControl)    
         
        Case 1
            Me.ActiveControl = "00" & Me.ActiveControl
            
        Case 2
            Me.ActiveControl = "0" & Me.ActiveControl
    
    End Select
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Thank you.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Or instead of CASE:

    Me.controlname = IIf(IsNull(Me.controlname), Null, Right("00" & Me.controlname, 3))
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 07-13-2021, 11:42 PM
  2. Input Mask
    By Serge-Nanaimo in forum Access
    Replies: 10
    Last Post: 02-15-2017, 09:10 PM
  3. Input Mask
    By warmanlord in forum Access
    Replies: 11
    Last Post: 10-15-2015, 10:01 AM
  4. Replies: 7
    Last Post: 09-06-2012, 06:04 AM
  5. Input mask
    By doobybug in forum Access
    Replies: 2
    Last Post: 06-17-2009, 09:40 PM

Tags for this Thread

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