Richard said:
Hi Bruce...
I think the parentheses are OK. Is not the closing parenthesis you mention the
closer for the dateserial function? {The opening parenthesis coming after the
word DateSerial}
It is interesting that it would not work for you either. I know that the
default value wants to see a string, and a traditional date string absolute is
enclosed by #s. Maybe Marsh has some input on this!
I'm getting lost here. What are you guys using and where
are you using it?
If you are trying to place the expression:
=Format(DateSerial(Year(Date()),Month(Date()),1),"m\/d\/yyyy")
directly in the DefaultValue property, you are telling
Access to use the text string 9/1/2006 as the value when a
new record is created (the result of the expression is a
string because the Format function always returns a string
value). This is distinctly different from using a date
value as the default. If the bound field is a date type
field, it should not accept a text string (although Access
coerces types so often it's difficult to be sure what
actually happens). When you include the # signs, you are
telling Access to use #9/1/2006# as the default value, which
is a Date type value.
All that is not related to our original discussion about
using VBA code to set the DefaultValue. Don't get lost in
all the various levels of evaluations. When you use a
statement in a VBA procedure, VBA first processes the
statement and stores the result (a text string that is
itself an expression) in the DefaultValue property. Then,
when the default value is applied, Access (different from
VBA) evaulates the **expression** in the property and the
result of that evaluation is the value placed in the
control's Value property.
If you just want to have the default value property to be
the first of the current month without using VBA, you can
set the DefaultValue property in form design to the
expression:
=DateSerial(Year(Date()),Month(Date()),1)
and don't forget that the = sign is optional.