Leading Zeros and Number Datatype?

V

Vi

Hi,

I have a row that has a datatype of "text", I have converted it to a
"number" by using Cdbl. But when I want to put leading zeros in front of the
converted row, the datatype becomes a text again.

For example:
0001 (text)
1 (number)
When I use format([field],"00000",5) it becomes a text again

My understanding is that the format should not convert the number back to a
text datatype.

Can someone explain what is happening here?
Thanks
V
 
B

BruceM

I don't know the source of your understanding about the Format function, but
from Help about the Format function:
Returns a Variant (String) ...
I can't really describe how a variant (string) differs from a text string
(except a variant can be null), but Help shows that it is indeed a string.

If you describe why you convert it into a number, then back into a string,
it may be possible to come up with a solution.
 
J

John W. Vinson

My understanding is that the format should not convert the number back to a
text datatype.

Settting the format property of a textbox or field doesn't affect the
datatype, but the VBA function Format() does return a Text value.
 
B

Brendan Reynolds

Vi said:
Hi,

I have a row that has a datatype of "text", I have converted it to a
"number" by using Cdbl. But when I want to put leading zeros in front of
the
converted row, the datatype becomes a text again.

For example:
0001 (text)
1 (number)
When I use format([field],"00000",5) it becomes a text again

My understanding is that the format should not convert the number back to
a
text datatype.

Can someone explain what is happening here?
Thanks
V


Well, numbers don't have leadings zeros, and the Format function does return
a string (text). Actually, to be a little more specific, there are two
versions of the Format function, Format$() and Format(). Format$() returns a
string, Format() returns a variant of sub-type string.

The bottom line is that the behavior you are seeing is the expected and
documented behavior. If you can describe what it is that you're trying to
accomplish, perhaps someone can help you achieve it.
 

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