Microsoft Calendar Control 10.0 and later versions use an incorrect value for the FirstDay property (826761)
The information in this article applies to:
- Microsoft Office Access 2003
- Microsoft Access 2002
This article applies to a Microsoft
Access database (.mdb) and a Microsoft Access project (.adp).
Moderate: Requires basic macro, coding, and interoperability
skills.
SYMPTOMSIn a Microsoft Access form or report, you insert Microsoft
Calendar Control 10.0 or a later version and then you try to set the FirstDay property of the Calendar Control by using the numeric constants.
For example, you use vbMonday for the days, as the "Help
Topics: Calendar Control Reference" Help file (Mscal.hlp) suggests. An
incorrect day is set for the first day of the Calendar
Control.
However, if you use the earlier versions of Calendar Control,
the FirstDay property is set correctly.CAUSEThis problem occurs because the numeric constants for the
days that are defined in Microsoft Visual Basic, such as
vbSunday and vbMonday, are not associated
with the correct day value.WORKAROUNDTo work around this problem, follow these steps:
- Determine the association between the days and the
Microsoft Visual Basic for Applications (VBA) intrinsic numeric constants. To
do this, follow these steps:
- Start Access.
- Open the Northwind.mdb sample database.
- In the Database window, click Forms
under Objects.
- In the right pane, double-click Create form in
Design view.
- On the Insert menu, click
ActiveX Control.
- 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.
- Click OK.
- Add a command button to the form that has the
properties set as follows:
Property | Value | Name | testFD | Caption | Change First
Day |
- On the File menu, click
Save.
- In the Save As dialog box, type
Form1 in the Form Name box, and then
click OK to save the Form1 form.
- On the View menu, click
Code.
- In the Visual Basic Editor, type or paste the following
code:
Option Compare Database
Private Sub testFD_Click()
Calendar0.FirstDay = vbTuesday
End Sub
- Open Form1 in the Form view.
- Click the Change First Day
button.
- If the first column of the Calendar Control is not set
to Tuesday, take note of the day in the first column.
- In the Visual Basic Editor, click Immediate
Window on the View menu.
- In the Immediate window, type
?vbTuesday, and then press ENTER.
Notice the
numeric value. - Repeat step k through step p by replacing
vbTuesday with other numeric constants, such as
vbMonday and vbWednesday. Create a table as
follows:
|
Monday | vbSunday | 1 | Tuesday | vbMonday | 2 | Wednesday | vbTuesday | 3 | Thursday | vbWednesday | 4 | Friday | vbThursday | 5 | Saturday | vbFriday | 6 | Sunday | vbSaturday | 7 |
- Create a global custom enumeration that is correctly mapped
to the week days. To do this, follow these steps:
- In the Database window, click Module
under Objects.
- On the Insert menu, click
Module.
- 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 "Week Day" column and
in the corresponding "Numeric Value Associated" column of the table that is in
step 1r. - Type Day_Association in the
Module Name box, and then save the module.
- Close the Visual Basic Editor.
- 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 isCalendar0.FirstDay = vbTuesday modify your code to use custom enumeration as follows:Calendar0.FirstDay = nwTuesday - Run the application.
REFERENCESFor more information about Calendar Control and the Calendar
Control properties, open Mscal.hlp and then search for the appropriate topic.
Mscal.hlp is located in the following folders:
Microsoft Access
2002
Installation Drive:\Program
Files\Microsoft Office\Office10
Microsoft Office Access
2003
Installation Drive:\Program
Files\Microsoft Office\Office11
Note Installation Drive is a placeholder for
the name of your installation drive.
Modification Type: | Minor | Last Reviewed: | 6/3/2004 |
---|
Keywords: | kbDateTime kbfunctions KbVBA kbCtrl kbProperties kbhelp kbprb KB826761 kbAudDeveloper |
---|
|