adding leading zeros based on LEN

burnout

Registered User.
Local time
Yesterday, 20:04
Joined
Jan 26, 2006
Messages
17
I have a text field that has preceding zeros, the total LEN is 12, so for instance the field would be 000000561803 or 000001012304 (can have anywhere from 2 to 7 preceding 0's).

I am curious if there is a way to add a control to the form field to add X number of 0's to the string to make the string length 12, so the user can just type 561803 and on tabbing out of the field six 0's would be added or in the other example the user can ad 1012304 and 5 0's would be added?

Thanks so much for your help!
 
Code:
Public Function SetNulFormat(intNumber As Integer) As String
    Dim strRetVal As String
    
    strRetVal = "0"
    If intNumber > 1 Then
        strRetVal = strRetVal & Replace(Space$(intNumber - 1), " ", "#")
    End If
    SetNulFormat = strRetVal
End Function
Test in your intermediate window:
Code:
? Format("7687", SetNulFormat(10))
0000007687
Enjoy!
 
Why not just use the format feature to display it the way you want as:

"000000000000"
 
Last edited:
And, if you absolutely NEED to set it to SAVE as 12 digits, the EASY code to save it as such would be:

Me!YourFieldNameHere = Format(Me!YourFieldName,"000000000000")

No other code necessary.
 
Ofcourse. When it is fixed to 12 use Bob's method!
 
Did you try it?
What was the result?
Was the result satisfactory?
What must it look like?
 
left("000000000000", 12-len(strTextToTest)) & strTextToTest

this will work for any number of decimal places. it will count the dot.
 
left("000000000000", 12-len(strTextToTest)) & strTextToTest

this will work for any number of decimal places. it will count the dot.

Thanks a lot
I have already solved it the same way....
 

Users who are viewing this thread

Back
Top Bottom