>Hi Antonio,
>
>Set century is on and date format is mm/dd/yyyy. Is this the one your asking?
>
>Here is the code: .OleDatePicker4.Change (EndDate)
>
>
>
>
>LOCAL lcMonth, lcDate, lcDay, lcYear, lcTime
>
>With This
> lcDay = STR(.Day,2)
> lcYear = STR(.Year,4)
> lcMonth = STR(.Month,2)
>* lcTime = str(.Time())
> lcDate = lcMonth +"/" + lcday+"/"+lcYear
>
> WITH ThisForm
> .txtEndDate.Value=ctod(lcDate)
>* .txtEndDate.setfocus()
>
>**** Check if end date (.OleDatePicker4) is earlier than start date (. (OleDatePicker3)
> IF .txtEndDate.Value <= .txtStartDate.Value
> .txtStartDate.Value=.txtEndDate.Value - 1
>
>*** Replace the following
> .OleDatePicker3.Month=MONTH(.txtStartDate.Value)
> .OleDatePicker3.Day=Day(.txtStartDate.Value)
> .OleDatePicker3.Year=Year(.txtStartDate.Value)
>
> ENDIF
> ENDWITH
>ENDWITH
>
>
>
>the error happens only on these dates between April 1-3, for example when startdate is April 2 and enddate is april 3, when i change enddate to april 1, startdate shlould change to Mar 31. but it doesn't change on the date picker and this error message appears, but it does change the value on the (textbox) .txtStartdate
>
>
>Thanks,
>
>Sonny
The problem is that, since you're setting the date an element at a time, when you set an element you may entering an invalid date, taking in account the setting of the other two.
For instance, imagine that the control holds the dates {^2017-03-31}. If you try to set the next day, but start the setting with the month by changing from 3 to 4, you actually are setting {^2017-04-31}, which is invalid. The same problem occurs when the current month is 2 (for instance) and you try to change the day to April 30th, for instance, and leave the month change for last (for a moment, the date will be {^2017-02-30}).
If you start by setting the day to 1 (in fact, any number lower than 29), then the other two elements (month and year), and finally the real day number you're initializing, then it should be ok.
----------------------------------
António Tavares Lopes