Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.DefaultValue = wrong date

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
With a text box on my form format = ShortDate and the code below
I get 12/30/1899

Code:
Private Sub Form_Load()
Forms!frmLogInOut!txtStartDate.DefaultValue = CDate("5/20/2006")
End Sub

But if I change the Value Directly in the text box Default property
to =CDate("5/20/2006") it works

why am I getting the wrong date using the VBA code??




Newbie in search of knowledge
 
Hi!

As a guess I would say that it is because the control is already loaded before the default value is set. If the control is bound to a field in a table you can set the default value in the table to avoid this.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
I had to pass the value as a string weird

Code:
Forms!frmLogInOut!txtStartDate.DefaultValue = "=Format(CDate('5/20/2006'), 'mm/dd/yyyy')"



Newbie in search of knowledge
 
Hi!

Well duh, I knew that, all the properties like that are strings.



Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top