Setting the default value using code, removes leading zero on text fields!!!!

  • Thread starter Thread starter Savvoulidis Iordanis
  • Start date Start date
S

Savvoulidis Iordanis

As sbj.
When the default value is displayed after set to "04523443", it displays
"523443"

I use Access 2000, Win2K Pro
 
Savvoulidis said:
As sbj.
When the default value is displayed after set to "04523443", it displays
"523443"

I use Access 2000, Win2K Pro


Either the field is a numeric field or you have specified a
numeric kind of format to the text box.

If the field is numeric and you didn't specify a format,
then you have to specify the exact format that you want to
see, probably just set it to 00000000

Note that the value stored in the table is not affected by
whatever format you choose to use to display the value.
 
The field is text and yes, I have a mask like 000000000.
Because the value is stored as a foreign key, I can't use it because of this
problem.
A workaround is to pass """" & number & """", as I found out.
 
Savvoulidis said:
The field is text and yes, I have a mask like 000000000.
Because the value is stored as a foreign key, I can't use it because of this
problem.
A workaround is to pass """" & number & """", as I found out.


Not sure I understand. Depending on what you mean by
"pass", that would be the correct way to use the field in
most contexts. In those cases, the quotes are not a
"workaround", they are required when comparing two text
fields.
 
I mean that when I call the function to pass the FK,
I use sth like : FuncName( parm )
where parm = """042514213"""

and not parm= "042514213"
 
Savvoulidis said:
I mean that when I call the function to pass the FK,
I use sth like : FuncName( parm )
where parm = """042514213"""

and not parm= "042514213"


Let's try to leave your function out of this and deal with
the DefaultValue property by itself. The first thing to
remember is that the DefaultValue property is a string
valued property so if you only use:

ctl.DefaultValue = "01"

then when the 01 is used in the control's Value it looks
like the number 01 and the leading zero is not relevant.

In order to tell the control that the Value is a string, it
has to have the quotes around it so you would assign it this
way:

ctl.DefaultValue = """01"""

then the control's Value would receive "01" and it would
know it is a text value.

This really is confusing, but the bottom line is that it's
not a workaround and you've done it the right way.
 
Back
Top