Removing leading zero's using InStr (1 Viewer)

Howlsta

Vampire Slayer
Local time
Today, 17:22
Joined
Jul 18, 2001
Messages
180
Greetings Folks!

I'm trying to write code to remove zero's from the start of a road number. The problem is that there are normally between 1-3 zero's at the start, so i'm not sure now to set up the expression sought. I then want to "trim" off the zero's. Anyway I'm having problems achieving the first bit, I think it is probably easy if you know now.

Any Ideas?

Rich
 

ColinEssex

Old registered user
Local time
Today, 17:22
Joined
Feb 22, 2002
Messages
9,126
If the road number is only a number, make the field a number (not text) and the leading zero's will be removed.

Col
 

Howlsta

Vampire Slayer
Local time
Today, 17:22
Joined
Jul 18, 2001
Messages
180
The problem is not that simple unfortunately ):
I'm running some code that checks a another field (road type), depending on the integer in the road type field the code adds a letter in front of the road number, eg M (motorway) A,B,C or nothing if it is not classified. The data can then be imported into Access, the code is supposed to put the data in the correct format for the import.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:22
Joined
Feb 28, 2001
Messages
27,309
If the thing you are working on is numeric, you might try something like this...

Assume the thing to be "de-zeroed" is in stData

If IsNumeric(stData) then

stData = CStr( CLng( stData ) )

end if

That double conversion should do the trick because the CStr will not restore the leading zeros removed by the CLng function.
 

Howlsta

Vampire Slayer
Local time
Today, 17:22
Joined
Jul 18, 2001
Messages
180
Thanks Doc,

The double conversion did exactly what you said.

Cheers

Rich
 

Users who are viewing this thread

Top Bottom