PRB: Error Setting DateTimePicker's Month Programmatically (189991)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q189991 SYMPTOMS
When you try to programmatically set the Month property of a DateTimePicker
control, you receive the following error message:
"Run-time error '380': Invalid property value"
If you use the drop-down Calendar to change the Month for the same date, it
works correctly.
CAUSE
When you change the Month property through the DateTimePicker control's
Calendar interface, it handles adjusting the Day property to create a valid
date. But if you assign a value to the Month property in code and this
creates an invalid date, you receive the appropriate error message.
RESOLUTION
Check to ensure that the combination of the control's current Day and Year,
along with the Month you wish to assign, combine to create a valid date.
Another approach you can take is to use the DateAdd function to change the
value of the Month property of the DateTimePicker control by adding or
subtracting the appropriate number of months. Just like the control's
graphic interface, the DateAdd function will automatically adjust for
differences in the number of days in the various months.
STATUS
This behavior is by design.
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | kbprb KB189991 |
---|
|