A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

REMOVING LEADING ZERO



 
 
Thread Tools Display Modes
  #1  
Old May 13th, 2010, 05:13 PM posted to microsoft.public.access.queries
Jessica
external usenet poster
 
Posts: 299
Default REMOVING LEADING ZERO

I have loan numbers that consist of all numbers or alphanumeric fields. Not
all loan numbers have the same digits, however, they are all formatted to 35
character spaces. For example, one loan might be 123 (with zeros in front)
and another loan would be 1245523, and another could be 1234abc1345. I need
to format those with only numbers to a number value. I have used the Val()
function and it works perfect with only number values, but when there is a
loan that have alphanumeric, it shows up as 0. How do it have it show the
loan number with the text? For example loan 00000abc123 needs to read abc123.
  #2  
Old May 13th, 2010, 05:58 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default REMOVING LEADING ZERO

Jessica wrote:

I have loan numbers that consist of all numbers or alphanumeric fields. Not
all loan numbers have the same digits, however, they are all formatted to 35
character spaces. For example, one loan might be 123 (with zeros in front)
and another loan would be 1245523, and another could be 1234abc1345. I need
to format those with only numbers to a number value. I have used the Val()
function and it works perfect with only number values, but when there is a
loan that have alphanumeric, it shows up as 0. How do it have it show the
loan number with the text? For example loan 00000abc123 needs to read abc123.



I think you will need to create a function to do that:

Public Function Strip(v)
Dim k As Long
If IsNull(v) Then Exit Function

For k = 1 To Len(v) - 1
If Mid(v, k, 1) "0" Then Exit For
Next k

Strip = Mid(v, k)
End Function

--
Marsh
MVP [MS Access]
  #3  
Old May 13th, 2010, 08:48 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default REMOVING LEADING ZERO

You can nest IIFs like this --
IIf(left([loan number],1)"0",[loan number], Iif(mid([loan
number],2,1)"0",mid([loan number],2),iif(mid([loan
number],3,1)"0",mid([loan number],3),"xxx"))) AS Expr1

You will need as many layers as you might have leading zeros.

--
Build a little, test a little.


"Jessica" wrote:

I have loan numbers that consist of all numbers or alphanumeric fields. Not
all loan numbers have the same digits, however, they are all formatted to 35
character spaces. For example, one loan might be 123 (with zeros in front)
and another loan would be 1245523, and another could be 1234abc1345. I need
to format those with only numbers to a number value. I have used the Val()
function and it works perfect with only number values, but when there is a
loan that have alphanumeric, it shows up as 0. How do it have it show the
loan number with the text? For example loan 00000abc123 needs to read abc123.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.