Microsoft KB Archive/272532

= PRB: DateTimePicker Value Is Incorrect When You Enter Invalid Date =

Article ID: 272532

Article Last Modified on 9/27/2004

-

APPLIES TO

 Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows 95

 Microsoft Windows 98 Standard Edition

 Microsoft Windows Millennium Edition  Microsoft Visual Basic 6.0 Enterprise Edition, when used with:  Microsoft Windows 95</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows Millennium Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q272532

<div class="symptoms_section">

SYMPTOMS
When a form that contains a DateTimePicker control is loaded, and you change the date from today's date to &quot;00&quot;, the date should revert to its original value (today's date) because the date is invalid. However, on Windows 95, Windows 98 and Windows Millennium Edition (Me), the data that is contained in the value property displays the last day of the previous month instead of the today's date.

This behavior does not occur on Windows 2000 or Windows NT.

<div class="resolution_section">

RESOLUTION
To resolve this problem, test the Day property, and set it to the original value if an invalid date is entered as follows: <ol> Start a new project in Visual Basic. Form1 is created by default.</li> On the Project menu, click Components, and then select the Windows Common Controls 2 check box. Click OK.</li> On the form, find an instance of the DateTimePicker control.</li>  In the code module of Form1, paste the following code: Dim s As String

Private Sub DTPicker1_Change If DTPicker1.Day = 0 Then DTPicker1.Value = s   Else s = DTPicker1.Value End If End Sub

Private Sub Form_Load s = DTPicker1.Value End Sub </li> Press the F5 key to run the project. You see today's date in the DateTimePicker text area.</li> Change the date to 0 or 00. The date reverts to today's date.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> On a system that runs Window 95, Windows 98, or Windows Me, start a new project in Visual Basic. Form1 is created by default.</li> On the Project menu, click Components, and then select the Windows Common Controls 2 check box. Click OK.</li> On the form, find an instance of the DateTimePicker control.</li> Press F5 to run the project, and you see today's date in the DateTimePicker text area.</li> <li>Change the date to 0. This value immediately changes to &quot;00&quot; as the control tries to verify the date. Then, the date in DateTimePicker changes to &quot;0&quot; instead of today's date.</li> <li> If you examine the data that is contained in the value property, as demonstrated in the code below, the data displays the last day of the previous month. Private Sub Form_Click MsgBox DTPicker1.Value End Sub </li></ol>

Additional query words: dtpicker

Keywords: kbcmnctrls kbprb kbctrl KB272532

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.