Microsoft KB Archive/169599

= ACC: Calendar Control Adds One Day When Time Is After 12:00 PM =

Article ID: 169599

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition
 * Microsoft Access Developer's Toolkit 2.0

-



This article was previously published under Q169599



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When a Calendar Control is assigned a value that includes the time as well as the date, it displays a date one day greater than the value if the time is after 12:00 P.M.



CAUSE
You are using either the version of the Calendar Control that ships with Microsoft Access 97 or the version that ships with the Microsoft Access Developer's Toolkit 2.0, and the control is rounding the value that has been assigned to it. In a date serial number, the time portion is stored to the right of the decimal point. Therefore, the Calendar Control will round the date up if the time is after 12:00 P.M. As a result, it displays a date one day greater than the date of the value assigned to it.



RESOLUTION
Because the DateValue function doesn't recognize time information, you can apply DateValue to the value that you have assigned to the Calendar Control. For example, if you assign the value in a text box named CalendarDate to a Calendar Control named Calendar1, you can use the following line of code:

  Me!Calendar1.Value = DateValue(Me!CalendarDate)



STATUS
This behavior does not occur with the version of the Calendar Control that ships with Microsoft Access for Windows 95 version 7.0.



Steps to Reproduce Behavior
To reproduce this behavior in Microsoft Access 97, follow these steps:

 Open the sample database Northwind.mdb. Create a new form in Design view not based on any table or query. On the Insert menu, click ActiveX Control. In the Insert ActiveX Control dialog box, select Calendar Control 8.0, and click OK.</li> Change the Name property of the Calendar Control to Calendar1.</li> Add a new text box to the form. Change the Name property of the text box to CalendarDate.</li>  Set the AfterUpdate property of the CalendarDate text box to the following event procedure:

Private Sub CalendarDate_AfterUpdate Me!Calendar1.Value = Me!CalendarDate End Sub </li> View the form in Form view.</li> In the CalendarDate text box, type:

1/1/97 3:00 PM </li></ol>

Notice that the Calendar Control displays the date 1/2/97.

To reproduce this behavior in Microsoft Access 2.0, follow these steps:

<ol> Start Microsoft Access and open the sample database NWIND.MDB.</li> Create a new, blank form not based on any table or query.</li> On the Edit menu, click Insert Object. In the Insert Object dialog box, select Insert Control. Select Calendar Control from the Control Type list, and click OK.</li> Change the Name property of the Calendar Control to Calendar1.</li> Add a new text box to the form. Change the Name property of the text box to CalendarDate.</li>  Set the AfterUpdate property of the CalendarDate text box to the following event procedure:

Sub CalendarDate_AfterUpdate Me!Calendar1.Object.Value = Me!CalendarDate End Sub </li> Open the form in Form view.</li> In the CalendarDate text box, type:

1/1/97 3:00 PM </li></ol>

Notice that the Calendar Control displays the date 1/2/97.

<div class="references_section">