Default value using dateserial

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a textbox. The format of the textbox is set to mm//dd/yyyy.
In the form's module, I want to set the default value of the textbox using the dateserial function:

Private Sub Form_Open(Cancel As Integer)
Me!Textbox.DefaultValue = DateSerial(Year(Now), Month(Now), Day(Now))
End Sub

This returns 12/30/1899 as the value in the text box. Does anyone see what the problem may be?
PS The reason I use the dateserial function here is that this is a simplification of my code, I will be using the dateserial to manipulate the date in the final code.
Thanks!
 
DefaultValue is a string property, you need to assign it a string like this:
"=#02/14/2004#"

Private Sub Form_Open(Cancel As Integer)
Dim dt As Date
dt = Date
Me.Textbox.DefaultValue = Format(dt, "\=\#mm\/dd\/yyyy\#")
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

bd said:
I have a form with a textbox. The format of the textbox is set to mm//dd/yyyy.
In the form's module, I want to set the default value of the textbox using the dateserial function:

Private Sub Form_Open(Cancel As Integer)
Me!Textbox.DefaultValue = DateSerial(Year(Now), Month(Now), Day(Now))
End Sub

This returns 12/30/1899 as the value in the text box. Does anyone see what the problem may be?
PS The reason I use the dateserial function here is that this is a
simplification of my code, I will be using the dateserial to manipulate the
date in the final code.
 
Back
Top