Pad field length

M

MarkM

I have a table with item numbers that range from 6-8 characters in
length. What I want to try to accomplish is pad the end of those items
numbers that are less than 8 chars. with 0’s so they are 8 chars. long. So
item # ME850C will pad out to ME850C00. How can I do this in?
 
M

MarkM

I should probably have also stated that the table I would like to use is a
linked table coming from a CSV file from a query I have from a different
database.
 
A

Arvin Meyer [MVP]

MarkM said:
I have a table with item numbers that range from 6-8 characters in
length. What I want to try to accomplish is pad the end of those items
numbers that are less than 8 chars. with 0's so they are 8 chars. long. So
item # ME850C will pad out to ME850C00. How can I do this in?

Function RPad(S, ByVal C As String, N As Integer) As String
If Len(C) = 0 Then C = " "
If N < 1 Then
RPad = ""
Else
RPad = Left$(S & String$(N, Left$(C, 1)), N)
End If
End Function

? RPad("ME850C","0",8)
ME850C00
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
J

John Vinson

I have a table with item numbers that range from 6-8 characters in
length. What I want to try to accomplish is pad the end of those items
numbers that are less than 8 chars. with 0’s so they are 8 chars. long. So
item # ME850C will pad out to ME850C00. How can I do this in?

One sneaky way is to use an expression like

Right([ItemNumber] & "00000000", 8)

Use it as a calculated field in a query to just display the padded
value, or in an Update query to permanently (and irrevokably) update
the field.

John W. Vinson[MVP]
 
A

Arvin Meyer [MVP]

John Vinson said:
I have a table with item numbers that range from 6-8 characters in
length. What I want to try to accomplish is pad the end of those items
numbers that are less than 8 chars. with 0's so they are 8 chars. long. So
item # ME850C will pad out to ME850C00. How can I do this in?

One sneaky way is to use an expression like

Right([ItemNumber] & "00000000", 8)

Use it as a calculated field in a query to just display the padded
value, or in an Update query to permanently (and irrevokably) update
the field.

I think you meant:

Left([FieldName] & "00000000", 8)
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top