Extract part of a number

S

Silvio

How can I extract a number starting from the second digit? (e.g. 1234567 will
extract only 234567 or 4256 will extract only 256 and so on). The data is a
Long Interger.

Thanks.
Silvio
 
J

John Spencer

Mid(NumberField & "",2)

If you want the number value then
CLng(Mid(NumberField & "",2))

If number field can be null, then you will need to test for that to
avoid any errors.

IIF(NumberField is Not Null, CLng(Mid(NumberField & "",2)),Null)

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
S

Silvio

Thank you John this works, what's the difference between using "Mid" and
using "CLng" first?
 
J

John Spencer

Mid returns a string. CLng will change the string back into a number.
If you don't need to do any math on the string, then you can skip the
step of using Clng to convert the string of numbers back into a number.



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
J

John Spencer

Nice and it automatically handles nulls.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

Another method, which returns a number:

x = 1234567
? x mod 10^(len(x)-1)
2345657

y = 4256
? y mod 10^(len(y)-1)
256

Bob

John said:
Mid returns a string. CLng will change the string back into a number.
If you don't need to do any math on the string, then you can skip the
step of using Clng to convert the string of numbers back into a number.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
Thank you John this works, what's the difference between using "Mid" and
using "CLng" first?
[quoted text clipped - 22 lines]
Thanks.
Silvio
 

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