Re: Long Integer truncates 0 at beginning of number
- From: Piper <Piper@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Aug 2007 12:06:02 -0700
Let me see if I understand this correctly
I can leave the number as 27987 in the database, but if I need to show it,
say in a textbox, I can just format it like this:
Dim id as Long
id = 27987
sometextbox.value = Format(id, "000000")
Is that right?
If it is I'll be so excited!
--
Piper
"Klatuu" wrote:
No, I don't think you need to redo all your coding. If the field in the.
table where the value is stored is Numeric/Long, then anything that
references or modifies it as a number can be left as is.
The only time you need to present it as text is when you want to show it to
a human in that format. Then, you use the Format function or property as
Jeff said. That does not chage the original value or type unless you do so
specifically. For example, let's say you want to present it in a message box:
MsgBox "This Is A Formatted Number " & Format(lngSomeNumber, "000000")
Nothing has changed about the variable lngSomeNumber. It is just formated
for presentation so that it will always be presented with enought zeros to
make it six characters long.
If you want to change it to a string:
strConvertedNumber = Format(lngSomeNumber, "000000")
Now lngSomeNumber has still not changed, but we have a string variable that
contains a text representation of the number.
--
Dave Hargis, Microsoft Access MVP
"Piper" wrote:
Thanks for the response - I'm bummed, now I have to make it a string and
convert all that coding.
Oh well - I suppose I should have figured that out before I started coding!
Thanks
--
Piper
"Jeff Boyce" wrote:
Piper
Access is doing EXACTLY what you are telling it to do. Integers, Long or
otherwise, are whole numbers. From basic math, 1, 01, 001, and
00000000000000001 are all the same value, i.e,. 1!
If you need to show the digit 0 as the first character in a string of
characters (digits), then it is likely NOT a number (something you'd
add/subtract/multiply/divide). If you aren't doing math with it, maybe it's
"text", not "number".
Or, if you want to SEE preceding zeros on a true number (math, remember),
you can use the Format property or function to display those, regardless of
the value Access stores.
Regards
Jeff Boyce
Microsoft Office/Access MVP
"Piper" <Piper@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3AB225A2-2462-43FF-A6DD-2EB40BA27A93@xxxxxxxxxxxxxxxx
Hi -
I have a field of type Long, the data that goes in the field are numbers
like 027987 and 564982
Every time I enter a number with a 0 in front access takes the 0 out and
leaves me with 27987.
Is there anything I can do to keep the field type long? I've done a lot of
programming and I hate to loose it if I had to change the field type to
String.
Thanks
--
Piper
- Follow-Ups:
- Re: Long Integer truncates 0 at beginning of number
- From: John W . Vinson
- Re: Long Integer truncates 0 at beginning of number
- From: Klatuu
- Re: Long Integer truncates 0 at beginning of number
- References:
- Re: Long Integer truncates 0 at beginning of number
- From: Jeff Boyce
- Re: Long Integer truncates 0 at beginning of number
- From: Klatuu
- Re: Long Integer truncates 0 at beginning of number
- Prev by Date: RE: Tables and Forms
- Next by Date: Re: Command buttons
- Previous by thread: Re: Long Integer truncates 0 at beginning of number
- Next by thread: Re: Long Integer truncates 0 at beginning of number
- Index(es):
Relevant Pages
|