TextBox DefaultValue

  • Thread starter Thread starter Rohit Thomas
  • Start date Start date
R

Rohit Thomas

Hello All,

I have the following code that I am trying to use to
change the default value of a textbox named ArcDelDate on
my form:

Me.ArcDelDate.DefaultValue = DLookup
("[ArchiveComplete]", "tblFileDate")

This should return the date 4/14/2004, however it returns
the following number: 0.000142571998859424. If I place the
DLookup statement in the Default Value properties of the
textbox, the date displays correctly when the form is
opened. Can someone tell me what I'm doing wrong? I would
like to set the default value of the textbox using code
since it will change depending on certain conditions.

Thanks,
Rohit Thomas
 
Rohit Thomas said:
Hello All,

I have the following code that I am trying to use to
change the default value of a textbox named ArcDelDate on
my form:

Me.ArcDelDate.DefaultValue = DLookup
("[ArchiveComplete]", "tblFileDate")

This should return the date 4/14/2004, however it returns
the following number: 0.000142571998859424. If I place the
DLookup statement in the Default Value properties of the
textbox, the date displays correctly when the form is
opened. Can someone tell me what I'm doing wrong? I would
like to set the default value of the textbox using code
since it will change depending on certain conditions.

Thanks,
Rohit Thomas

0.000142571998859424 is the result of the arithmetic expression (4 / 14)
/ 2004. You need to specify the DefaultValue property as a string
expression that evaluates to a date:

Me.ArcDelDate.DefaultValue = _
Format( _
DLookup("[ArchiveComplete]", "tblFileDate"), _
"\#mm/dd/yyyy\#")

You could also specify it as a string expression that evaluates to a
string expression that can be converted to a date:

Me.ArcDelDate.DefaultValue = _
Chr(34) & _
DLookup("[ArchiveComplete]", "tblFileDate") & _
Chr(34)
 
Hi Rohit

The DefaultValue property is a string. What is happening is the string
"4/14/2004" is being interpreted as an arithmetic expression: 4 ÷ 14 ÷ 2004.

To prevent this, enclose the value in quote marks:

Me.ArcDelDate.DefaultValue = Chr(34) & DLookup _
("[ArchiveComplete]", "tblFileDate") & Chr(34)
 
Thanks Dirk and Graham....

Both suggestions work great. I attempted to use the format
and quotes option before you replied, but my code had
errors in it. Thanks again for the reply.
 
Back
Top