Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Mask - Leading Zeros

Status
Not open for further replies.

darall

Instructor
Aug 7, 2002
32
US
Trying to create a Text Box on a Form that has a 10 digit part number. This number should be 10 digits total, however with some part numbers the actual number may only be 5 or 6 characters. I am trying to create a mask that will replace any characters I do not type with a zero. So if I type 123 it stores 0000000123.

Any help would be very much appreciated.
Thanks
 
Check out the following Online Help topic in Access:

Format Property - Number and Currency Data Types

In particular the section on Custom formats.

HTH
Lightning
 
Thanks for the tip, however I though it was taboo to store a field that is not used for calculation as number or currency. Since this is a part number shouldn't it be stored as text?
 
OK, if your using a text field, try this code

Code:
'***************************************************************************************
'
'Written by Anders Falk
'Published in Access/Office/VB Advisor Magazine
'December 1997
'
'***************************************************************************************

Function FillZero(Pad As Variant) As Variant
'Zero Fills non-numerical "Number" fields for sorting purposes.
    
    Const MaxDigits = "00000000000000"  'Amend this to the number of digits required
    Dim i As Integer
    Dim c As String
    Dim Buf As String
    Dim PadNum As String
    
'Don't convert nulls
    If IsNull(Pad) Then
        FillZero = Null
        Exit Function
    End If
    
    For i = 1 To Len(Pad)
        c = Mid$(Pad, i, 1)
        If InStr("0123456789", c) Then
            If PadNum = "" Then PadNum = MaxDigits
            PadNum = Mid$(PadNum, 2) & c
        Else
            If PadNum <> "" Then
                Buf = Buf & PadNum
                PadNum = ""
            End If
            Buf = Buf & c
        End If
    Next i
    If PadNum <> "" Then Buf = Buf & PadNum
    FillZero = Buf
    
End Function

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top