jsalestrom70
asked on
Padding with zeros with a dash
I have a field in a query 12345-1234 that I need to pad to 012345-001234
Each side must have 6 digits. How can I do this in a microsoft access query?
Thanks
Jaymes
Each side must have 6 digits. How can I do this in a microsoft access query?
Thanks
Jaymes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use this function (alt+F11, copy paste)
Function myFormat(s As String)
Dim n1 As String, n2 As String
Dim ns() As String
ns = Split(s, "-")
n1 = "000000" & ns(0)
n2 = "000000" & ns(1)
myFormat = Right(n1, 6) & "-" & Right(n2, 6)
End Function
SELECT myFormat("1234-5678")
001234-005678
Select query:
SELECT Table1.FIELD0 AS FIELD0Before, Format(Replace([FIELD0],"- ",""),"000 000-000000 ") AS FIELD0After
FROM Table1
WHERE (((Nz([FIELD0],"")>"")=Tru e));
Update Query - make a BACKUP first:
UPDATE Table1 SET Table1.FIELD0 = Format(Replace([FIELD0],"- ",""),"000 000-000000 ")
WHERE (((Nz([FIELD0],"")>"")=Tru e));
mx
SELECT Table1.FIELD0 AS FIELD0Before, Format(Replace([FIELD0],"-
FROM Table1
WHERE (((Nz([FIELD0],"")>"")=Tru
Update Query - make a BACKUP first:
UPDATE Table1 SET Table1.FIELD0 = Format(Replace([FIELD0],"-
WHERE (((Nz([FIELD0],"")>"")=Tru
mx
MX,
If you try that on the sample input 12345-1234, the result you get back is 000123-451234.
:)
Patrick
If you try that on the sample input 12345-1234, the result you get back is 000123-451234.
:)
Patrick
yep ... missed that
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
newvalue: "0" & left (fieldname, 6) & "00" & right(fieldname, 4)