DOCUMENT:Q253785 23-FEB-2000 [foxpro] TITLE :PRB: Error When Setting DateTimePicker Control Programmatically PRODUCT :Microsoft FoxPro PROD/VER:WINDOWS:6.0 OPER/SYS: KEYWORDS:kbActiveX kbCtrl kbvfp600 kbGrpDSFox kbDSupport ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, version 6.0 ------------------------------------------------------------------------------- SYMPTOMS ======== When attempting to set the date of a DateTimePicker control programmatically, the following error message might appear: OLE IDispatch exception code 0 from DTPicker: Invalid Property Value. CAUSE ===== When using the DateTimePicker control's Calendar interface to change the date, the control handles adjusting the Day, Month, and Year properties to create a valid date. If a value is assigned that creates an invalid date, the error message above is displayed. RESOLUTION ========== Use the GOMONTH() function to return a valid date, which can then be used to set the Day, Month, and Year properties of the DateTimePicker control as follows: olddate=exampledate exampledate=exampledate+(number_of_days_to_change) IF MONTH(exampledate)<>MONTH(olddate) olddate=GOMONTH(olddate,-1) THISFORM.DTPicker1.DAY=DAY(olddate) THISFORM.DTPicker1.MONTH=MONTH(olddate) THISFORM.DTPicker1.YEAR=YEAR(olddate) ENDIF STATUS ====== This behavior is by design. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 1. Create a program file named "DTP_DEMO" (without the quotation marks) using the following code: PUBLIC OX OX=CREATEOBJECT('MYFORM') OX.SHOW READ EVENTS DEFINE CLASS myform AS FORM CAPTION = "DateTimePicker Form" HEIGHT = 150 LEFT = 0 TOP = 0 WIDTH = 230 NAME = "myform" ADD OBJECT DTPicker1 AS OLECONTROL WITH ; OLECLASS="MSComCtl2.DTPicker.2",; TOP = 5, ; LEFT = 5, ; HEIGHT = 25, ; WIDTH = 100, ; NAME = "DTPicker1" ADD OBJECT commandbutton1 AS COMMANDBUTTON WITH ; TOP=45, ; LEFT=115, ; HEIGHT=25, ; AUTOSIZE=.T., ; CAPTION="Add One Day", ; NAME="commandbutton1" ADD OBJECT commandbutton2 AS COMMANDBUTTON WITH ; TOP=75, ; LEFT=115, ; HEIGHT=25, ; AUTOSIZE=.T., ; CAPTION="Subtract One Day", ; NAME="commandbutton2" ADD OBJECT commandbutton3 AS COMMANDBUTTON WITH ; TOP=125, ; LEFT=125, ; HEIGHT=25, ; CAPTION="\MONTH(olddate) *!* olddate=GOMONTH(olddate,1) *!* THISFORM.DTPicker1.DAY=DAY(olddate) *!* THISFORM.DTPicker1.MONTH=MONTH(olddate) *!* THISFORM.DTPicker1.YEAR=YEAR(olddate) *!* ENDIF THISFORM.DTPicker1.DAY=DAY(exampledate) THISFORM.DTPicker1.MONTH=MONTH(exampledate) THISFORM.DTPicker1.YEAR=YEAR(exampledate) ENDPROC PROCEDURE commandbutton2.CLICK olddate=exampledate exampledate=exampledate-1 *!* IF MONTH(exampledate)<>MONTH(olddate) *!* olddate=GOMONTH(olddate,-1) *!* THISFORM.DTPicker1.DAY=DAY(olddate) *!* THISFORM.DTPicker1.MONTH=MONTH(olddate) *!* THISFORM.DTPicker1.YEAR=YEAR(olddate) *!* ENDIF THISFORM.DTPicker1.DAY=DAY(exampledate) THISFORM.DTPicker1.MONTH=MONTH(exampledate) THISFORM.DTPicker1.YEAR=YEAR(exampledate) ENDPROC PROCEDURE commandbutton3.CLICK RELEASE THISFORM ENDPROC PROCEDURE UNLOAD CLEAR EVENTS ENDPROC ENDDEFINE 2. Save and run DTP_DEMO. 3. Click the Command button captioned Subtract One Day, and note the error message that appears. 4. Uncomment the commented lines of code in the commandbutton1.click and commandbutton2.click methods. 5. Save and run DTP_DEMO. 6. Click the Command button captioned Subtract One Day, and note that the error message does not appear. (c) Microsoft Corporation 2000, All Rights Reserved. Contributions by John Desch, Microsoft Corporation. REFERENCES ========== For additional information DTPicker ActiveX Control, click the article number below to view the article in the Microsoft Knowledge Base: Q189991 PRB: Error Setting DateTimePicker's Month Programmatically Additional query words: ====================================================================== Keywords : kbActiveX kbCtrl kbvfp600 kbGrpDSFox kbDSupport Technology : kbVFPsearch kbAudDeveloper kbVFP600 Version : WINDOWS:6.0 Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2000.