PRB: DateTimePicker Value Is Incorrect When You Enter Invalid Date (272532)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 6.0, when used with:
- the operating system: Microsoft Windows 95
- the operating system: Microsoft Windows 98
- the operating system: Microsoft Windows Millennium Edition
- Microsoft Visual Basic Enterprise Edition for Windows 6.0, when used with:
- the operating system: Microsoft Windows 95
- the operating system: Microsoft Windows 98
- the operating system: Microsoft Windows Millennium Edition
This article was previously published under Q272532 SYMPTOMS
When a form that contains a DateTimePicker control is loaded, and you change the date from today's date to "00", 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.
RESOLUTION
To resolve this problem, test the Day property, and set it to the original value if an invalid date is entered as follows:
- Start a new project in Visual Basic. Form1 is created by default.
- On the Project menu, click Components, and then select the Windows Common Controls 2 check box. Click OK.
- On the form, find an instance of the DateTimePicker control.
- 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
- Press the F5 key to run the project. You see today's date in the DateTimePicker text area.
- Change the date to 0 or 00. The date reverts to today's date.
Modification Type: | Minor | Last Reviewed: | 9/27/2004 |
---|
Keywords: | kbCmnCtrls kbCtrl kbprb KB272532 |
---|
|