DEFINE CLASS txtdate AS textbox Alignment = 3 Value = {} *-- Used to store the actual DateTime ControlSource of the control so we can enter Data Values and update the "real" datetinme controlsource manually behind the scenes ccontrolsource = "" Name = "txtdate" *-- Called from the Valid to update the field specified in the cControlSource property from the control's value. It expects the specified field to of data type datetime. PROCEDURE updatecontrolsource LOCAL ldValue, lcField, lcAlias ldValue = IIF( VARTYPE( This.Value ) = 'T', TTOD( This.Value ), This.Value ) lcField = JUSTEXT( This.cControlSource ) lcAlias = JUSTSTEM( This.cControlSource ) *** Update cControlSource from the Control's Value IF NOT EMPTY( This.cControlSource ) IF EMPTY( NVL( ldValue, {} ) ) *** Check to see if we are updating a form property IF UPPER( LEFT( This.cControlSource, 4 ) ) == 'THIS' lcControlSource = This.cControlSource &lcControlSource = {/:} ELSE REPLACE ( lcField ) WITH .NULL. IN ( lcAlias ) ENDIF ELSE *** make sure we have a valid date *** so we do not get datetime overflow errors *** in sql server when we attempt an update IF NOT( UPPER( LEFT( This.cControlSource, 4 ) ) == 'THIS' ) IF BETWEEN( ldValue, {^1900-01-01}, {^3000-01-01} ) REPLACE ( lcField ) WITH DTOT( ldValue ) IN ( lcAlias ) ELSE MESSAGEBOX( 'Invalid Date', 16, 'Please Fix Your Input' ) RETURN .F. ENDIF ELSE lcControlSource = This.cControlSource &lcControlSource = DTOT( ldValue ) ENDIF ENDIF ENDIF ENDPROC *-- Refreshes the control's (DATE) value from the datetime value conained in the field specified in its cControlSource property PROCEDURE refreshvalue LOCAL ltValue IF NOT EMPTY( This.cControlSource ) ltValue = EVALUATE( This.cControlSource ) *** Update the control's value from its cControlSource IF EMPTY( NVL( ltValue, {/:} ) ) This.Value = {} ELSE IF VARTYPE( ltValue ) = 'T' This.Value = TTOD( ltValue ) ELSE This.Value = ltValue ENDIF ENDIF ELSE This.Value = {} ENDIF ENDPROC PROCEDURE Init *** Unbind the control and save the controlsource to a special property IF NOT EMPTY( This.ControlSource ) This.cControlSource = This.ControlSource This.ControlSource = '' ENDIF This.Format = 'D' This.Value = {} ENDPROC PROCEDURE Valid IF NOT This.UpdateControlSource() RETURN 0 ENDIF ENDPROC PROCEDURE Refresh This.RefreshValue() ENDPROC ENDDEFINE