> Is there an Access function (or combination of functions) that can remove
> leading zeroes from a text string?
Does the text string contain numbers after the leading zeros?
=Val("0005670")
returns 5670 as a number.
=Val("000ABC")
returns 0.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
If its a text string you have to search:
Public Sub RunMe()
Dim strValue As String
Dim strNewValue As String
strValue = "000A1B2C300"
strNewValue = RemoveLeadingZeros(strValue)
MsgBox Prompt:="The string without leading zeros is: " & strNewValue
End Sub
Public Function RemoveLeadingZeros( _
ByVal strValue) As String
' Test if there is at least 1 leading zero
If Left(strValue, 1) = "0" Then
Do While True 'fContinue 'And (intPosition <= intLen)
If Mid(strValue, 1, 1) = "0" Then
strValue = Replace(strValue, "0", "", 1, 1, vbTextCompare)
Else
' reached the first non-zero string
Exit Do
End If
Loop
Else
' Does not have a leading zero
End If
RemoveLeadingZeros = strValue
End Function
HTH
Rob Mastrostefano

Signature
FMS Professional Solutions Group
http://www.fmsinc.com/consulting
Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com
FMS Advanced Systems Group
http://www.fmsasg.com/
> Is there an Access function (or combination of functions) that can remove
> leading zeroes from a text string?
>Is there an Access function (or combination of functions) that can remove
>leading zeroes from a text string?
If it's numeric, use Val([fieldname]), or CStr(Val([fieldname])) to
get back to a string.
If it's text, or mixed numeric and text, after the zeros, you'll need
a little VBA function. Here's a recursive one off the top of my head,
test it first:
Public Function StripZeros(strIn As String) As String
If Left(strIn, 1) = "0" And Len(strIn) > 1 Then
StripZeros = StripZeros(Mid(strIn, 2))
Else
StripZeros = strIn
End If
End Sub
John W. Vinson[MVP]
RobFMS - 19 Nov 2005 05:51 GMT
John .. you did recursion ... eeewww!!! LOL!

Signature
FMS Professional Solutions Group
http://www.fmsinc.com/consulting
Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com
>
>>Is there an Access function (or combination of functions) that can remove
[quoted text clipped - 16 lines]
>
> John W. Vinson[MVP]
John Vinson - 19 Nov 2005 18:34 GMT
>John .. you did recursion ... eeewww!!! LOL!
A programmer who lived in Racine
Said "I can overload any machine -
My secret's aversion
To loops and recursion,
Just acres of inline routine!"
It's all right to write recursive code... just don't do it in public,
and wash your hands afterwards! <g>
John W. Vinson[MVP]
Tom Lake - 19 Nov 2005 18:42 GMT
>>Is there an Access function (or combination of functions) that can remove
>>leading zeroes from a text string?
> If it's text, or mixed numeric and text, after the zeros, you'll need
> a little VBA function. Here's a recursive one off the top of my head,
> test it first:
Why not use LTrim?
Tom Lake
Tom Lake - 19 Nov 2005 20:02 GMT
>>>Is there an Access function (or combination of functions) that can remove
>>>leading zeroes from a text string?
[quoted text clipped - 6 lines]
>
> Tom Lake
OK, I know why. I thought of spaces while reading Zeros. Never mind!
LTrim(Str(Val(n)))
should work, though.
Tom L
John Vinson - 19 Nov 2005 20:49 GMT
>OK, I know why. I thought of spaces while reading Zeros. Never mind!
>
>LTrim(Str(Val(n)))
>
>should work, though.
redundant since Val() already does the trimming... and it will fail
for input data such as "0000A32KW". The OP hasn't posted back with
more details so we may never know!
John W. Vinson[MVP]
Tom Lake - 19 Nov 2005 20:55 GMT
>>LTrim(Str(Val(n)))
>>
[quoted text clipped - 3 lines]
> for input data such as "0000A32KW". The OP hasn't posted back with
> more details so we may never know!
Not redundant since the Str function puts a leading space for positive
numbers.
Tom L