Richard said:
Au contraire! You did a fine job. Yes the syntax of strings certainly has
changed over the years! To make matters worse, ASP uses single quotes rather
than the traditional double quotes. (Arrrrgh) Quite familiar with chr$(34)!
The key was when you explained that the default value had to be enclosed in
quotes, as it is a string. Once understood--the mists cleared! Thanks again!
Now that you've mastered DefaultValue Lesson 2, let's move
on to Lesson 3 ;-)
The DefaultValue property is an **expression** that will be
evaluated when it is used in a new record. (Even though
Help says to use an = sign to get evaluation, I have found
the = sign to be optional.) This means that setting the
default value of a text box to something like either:
textbox.DefaultValue = "2+3"
or
textbox.DefaultValue = "=2+3"
will result in the new record having a 5 in the text box's
value. To actually get 2+3 as a text string in the text
box's value, you must use either:
textbox.DefaultValue = """2+3"""
or
textbox.DefaultValue = "=""2+3"""
Keep this in mind when you just want a string as the default
value. For example:
textbox.DefaultValue = "ABC"
will result in #Name because ABC is not a known name.
Again, you need to use:
textbox.DefaultValue = """ABC"""
OTOH, this may be useful(?) in a case where you want the
default value of a text box to be the concatenation of two
or more other unbound controls. Something of this nature
perhaps:
textbox.DefaultValue = "txtModel & ""-"" & txtSerialNo"
which could result in ABC-1234
This whole discussion can get rather complex/confusing with
default values that look like a date. For example:
textbox.DefaultValue = "7/4/06"
resulting value in textbox 0.291666666666667
textbox.DefaultValue = "#7/4/06#"
regulating value in textbox 7/4/06
textbox.DefaultValue = """7/4/06"""
regulating value in textbox 7/4/06
Note that the last example above is arrived at in a
roundabout way since the default value is really a string
that might, in some situations, be converted to a date
using the Windows date settings. I think(?) this is safe,
but there might(?) be some combinations of Windows settings
that would result in 7 Apr 06 so I always use the # date
delimiter as in the second example.
Think about all this and when the headache eventually
subsides, move on to Lesson 4 where you have to take into
account the data type of the field bound to the text box
and/or the text box's Format property ;-))