Connecting Tech Pros Worldwide Forums | Help | Site Map

Text box (Unbound) to Date Type

Newbie
 
Join Date: Nov 2008
Posts: 26
#1: Jan 9 '09
Hi all,

I have a text box in form and it contains date (get value from combo box). Now I want to convert/change this text box to date type.

Is the anyway I can do it?

Thank you so much.
Shimul

Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#2: Jan 10 '09

re: Text box (Unbound) to Date Type


Hi Shimul. To convert the text-based date in your textbox to a date type use the CDate function. Example in VBA:

Expand|Select|Wrap|Line Numbers
  1. Dim SomeDate as Date
  2. SomeDate = CDate(Forms![name of your form]![name of the textbox])
Date/Time values are stored internally as decimal values, with the whole number part the number of days from 1 Jan 1900, and the decimal part the time. CDate converts the text date to its equivalent date type (an elapsed days value essentially), applying the current regional settings for interpretation of the month and day parts.

-Stewart
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Jan 12 '09

re: Text box (Unbound) to Date Type


As Stewart says, there's not a way to make the TextBox control work as a Date control, but if you cast it on use (CDate()) then it should work for you reliably.
Reply