Microsoft KB Archive/826761

= Microsoft Calendar Control 10.0 and later versions use an incorrect value for the FirstDay property =

Article ID: 826761

Article Last Modified on 4/4/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



This article applies to a Microsoft Access database (.mdb) file or to a Microsoft Access database (.accdb) file.

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



SYMPTOMS
In Microsoft Access, an incorrect day is displayed for the first day of the Calendar Control. This problem occurs when you insert a Microsoft Calendar Control 10.0 or a later version into a form or into a report, and then you set the FirstDay property of the Calendar Control by using Microsoft Visual Basic for Applications (VBA) intrinsic constants.

For example, you set the FirstDay property of the Calendar Control to vbMonday or to vbTuesday. When you set the FirstDay property of the Calendar Control to vbTuesday, the calendar uses Wednesday as the first day of the week.

Note When you use the earlier versions of Calendar Control, you can set the FirstDay property correctly.



CAUSE
This problem occurs because the intrinsic constants for the days that are defined in Microsoft Visual Basic, such as vbSunday and vbMonday, are not associated with the correct day value.



WORKAROUND
To work around this problem, follow these steps:  Determine the association between the days, the VBA intrinsic constants, and the numeric values that are associated to the correct day values and VBA intrinsic constants. To do this, follow these steps:  Start Access. Open the Northwind sample database. In the Database window, click Forms under Objects.

Note In Access 2007, click the Create tab, and then click Form Design in the Forms group. In the right pane, double-click Create form in Design view.

Note In Access 2007, skip this step. On the Insert menu, click ActiveX Control.

Note In Access 2007, click the Design tab, and then click Insert ActiveX Control in the Controls group.</li> In the Insert ActiveX Control dialog box, click to select Calendar Control 10.0 or a later version from the Select an ActiveX Control list box, and then click OK.</li> Add a command button to the form that has the properties set as follows: </li> On the File menu, click Save.

Note In Access 2007, click the Microsoft Office Button, and then click Save.</li> In the Save As dialog box, type Form1 in the Form Name box, and then click OK to save the Form1 form.</li> On the View menu, click Code.

Note In Access 2007, click the Design tab, and then click View Code in the Tools group.</li>  In the Visual Basic Editor, type or paste the following code: Option Compare Database

Private Sub testFD_Click Calendar0.FirstDay = vbTuesday End Sub </li> Open Form1 in the Form view.</li> Click the Change First Day button.

Note If the first column of the Calendar Control is not set to Tuesday, note the day in the first column.</li> In the Visual Basic Editor, click Immediate Window on the View menu.</li> In the Immediate window, type ?vbTuesday, and then press ENTER.

Notice the numeric value.</li> Repeat step j through step o by replacing vbTuesday with other VBA intrinsic constants, such as vbMonday and vbWednesday.

Notice that you will have the following table to show the association between the days, the VBA intrinsic constants, and the numeric values that are associated to the correct day values and VBA intrinsic constants. </li></ol> </li> Create a global custom enumeration that is correctly mapped to the week days. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> In the Database window, click Module under Objects.

Note In Access 2007, click the Create tab, click the arrow under Macro in the Other group, and then click Module.</li> On the Insert menu, click Module.

Note In Access 2007, skip this step.</li>  Type or paste the following code in the Visual Basic Editor: Option Explicit Public Enum nwFirstDay nwMonday = 1 nwTuesday = 2 nwWednesday = 3 nwThursday = 4 nwFriday = 5 nwSaturday = 6 nwSunday = 7 End Enum Note Create the enumeration as described in the &quot;Week Day&quot; column and in the corresponding &quot;Numeric Value Associated&quot; column of the table that is in step 1r. </li> Name the Module Day_Association, and save it.</li> <li>Close the Visual Basic Editor.</li></ol> </li> <li> Replace the VBA intrinsic constants in your application with the constants that are in the custom enumeration that is described in step 2.

For example, if your original code is Calendar0.FirstDay = vbTuesday modify your code to use custom enumeration as follows: Calendar0.FirstDay = nwTuesday </li> <li>Run the application.</li></ol>

<div class="moreinformation_section">

MORE INFORMATION
The VBA intrinsic constants do not depend on the system local information. For example, on a computer that has the localized operating system in the German language, the first day of the week is Monday. The numeric value associated with Monday on the computer is always 0.

Because Calendar Control 10.0 or a later version is a worldwide Microsoft ActiveX control, you cannot control the numeric values that are associated with the VBA intrinsic constants based on your computer specifications. Therefore, the problem that is mentioned in the &quot;Symptoms&quot; section of this article occurs.

Steps to reproduce the problem
<ol> <li>Start Access.</li> <li>Open the Northwind sample database.</li> <li>In the Database window, click Forms under Objects.

Note In Access 2007, click the Create tab, and then click Form Design in the Forms group.</li> <li>In the right pane, double-click Create form in Design view.

Note In Access 2007, skip this step.</li> <li>On the Insert menu, click ActiveX Control.

Note In Access 2007, click the Design tab, and then click Insert ActiveX Control in the Controls group.</li> <li>In the Insert ActiveX Control dialog box, click to select Calendar Control 10.0 or a later version from the Select an ActiveX Control list box, and then click OK.</li> <li>Add a command button to the form that has the properties set as follows: </li> <li>On the View menu, click Code.

Note In Access 2007, click the Design tab, and then click View Code in the Tools group.</li> <li> In the Visual Basic Editor, type or paste the following code: Option Compare Database

Private Sub testFD_Click Calendar0.FirstDay = vbTuesday End Sub </li> <li>On the File menu, click Save.

Note In Access 2007, click the Microsoft Office Button, and then click Save As.</li> <li>In the Save As dialog box, type Form1 in the Form Name box, and then click OK to save the Form1 form.</li> <li>Open Form1 in the Form view.</li> <li>Click the Change First Day button.

Although you set the FirstDay property of the Calendar Control to vbTuesday, the calendar selects Wednesday to be the first day of the week.</li></ol>

<div class="references_section">