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

Last reviewed: June 5, 1997
Article ID: Q169599
The information in this article applies to:
  • Microsoft Access 97
  • Microsoft Access Developer's Toolkit, version 2.0

SYMPTOMS

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

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 PM.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

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 PM. 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.

MORE INFORMATION

Steps to Reproduce Behavior

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

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Create a new form in Design view not based on any table or query.

  3. On the Insert menu, click ActiveX Control.

  4. In the Insert ActiveX Control dialog box, select Calendar Control 8.0, and click OK.

  5. Change the Name property of the Calendar Control to Calendar1.

  6. Add a new text box to the form. Change the Name property of the text box to CalendarDate.

  7. 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
    
    

  8. View the form in Form view.

  9. In the CalendarDate text box, type:

          1/1/97 3:00 PM
    

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

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

  1. Start Microsoft Access and open the sample database NWIND.MDB.

  2. Create a new, blank form not based on any table or query.

  3. 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.

  4. Change the Name property of the Calendar Control to Calendar1.

  5. Add a new text box to the form. Change the Name property of the text box to CalendarDate.

  6. 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
    
    

  7. Open the form in Form view.

  8. In the CalendarDate text box, type:

          1/1/97 3:00 PM
    

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

REFERENCES

For more information about the DateValue() function, search the Help Index for "DateValue."


Keywords : IntpCstm kbusage
Version : 2.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Resolution Type : kbworkaround


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.

Last reviewed: June 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.