Calendar Control

The Calendar control displays a monthly calendar that you can insert in a form.

Filename

Mscal.ocx

Remarks

The Calendar control supports properties that you can use to set and retrieve the date and to control the appearance of the calendar. It supports methods that you can use to set the appropriate day, month, and year, to show an About box, and to repaint the calendar. It also supports events that notify your application when the user has moved to a new date on the calendar, when the user has clicked or double-clicked on a date, and when the user has pressed a key.


Calendar Control Properties

The following table describes the properties for the Calendar control.

Property	Description
BackColor	The background color for the Calendar control.
Day	The currently selected day of the month.
DayFont	The font used to display the days of the week in the Calendar control.
DayFontColor	The color used to display the days of the week.
DayLength	The format used to display days of the week.
FirstDay	The first day of the week that appears in the Calendar control.
GridCellEffect	The effect used to display the calendar.
GridFont	The font used to display the days of the month in the grid.
GridFontColor	The color used to display the days of the month.
GridLinesColor	The grid line color.
Month	The month currently displayed in a Calendar control.
MonthLength	The format used to display months of the year.
ShowDateSelectors	The visibility of the month and year date selectors.
ShowDays	The visibility of the days of the week.
ShowHorizontalGrid	The visibility of the horizontal grid lines.
ShowTitle	The visibility of the month/year title.
ShowVerticalGrid	The visibility of the vertical grid lines.
TitleFont	The font used to display the month/year title above the calendar grid.
TitleFontColor	The color to use when displaying the month/year title.
Value	The date value that corresponds to the selected date in the Calendar control.
ValueIsNull	The appearance of the current date as highlighted or not highlighted.
Year	The currently selected year.


Calendar Control Methods

The following table describes the methods for the Calendar control.

Method	Description
AboutBox	Displays the version and copyright information.
NextDay	Increments the value of the Calendar control by one day.
NextMonth	Increments the value of the Calendar control by one month.
NextWeek	Increments the value of the Calendar control by one week.
NextYear	Increments the value of the Calendar control by one year.
PreviousDay	Decrements the value of the Calendar control by one day.
PreviousMonth	Decrements the value of the Calendar control by one month.
PreviousWeek	Decrements the value of the Calendar control by one week.
PreviousYear	Decrements the value of the Calendar control by one year.
Refresh	Repaints the calendar.
Today	Sets the current date to today's date.


Calendar Control Events

The following table describes the events for the Calendar control.

Event	Description
AfterUpdate	Occurs after the user moves to a new date in the Calendar control and after the calendar has been repainted.
BeforeUpdate	Occurs after the user moves to a new date in the Calendar control but before the calendar has been redrawn.
Click	Occurs when the user clicks a date in the Calendar control.
DblClick	Occurs when the user double-clicks a date in the Calendar control.
KeyDown	Occurs when the user presses a key while the Calendar control has the focus.
KeyPress	Occurs when the user presses and releases an ANSI key while the Calendar control has the focus.
KeyUp	Occurs when the user releases a key while the Calendar control has the focus.
NewMonth	Occurs when the Calendar control date changes to a new month.
NewYear	Occurs when the Calendar control date changes to a new year.


BackColor Property (Calendar Control)

You can use the BackColor property to specify the background color that appears in the Calendar control.

Setting

The setting for the BackColor property is a Long value that represents an RGB color.

You can set this property in the Calendar control custom property sheet or in Visual Basic.

Remarks

You can specify an RGB color for the BackColor property using the Visual Basic RGB function. The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower three bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).

If the high byte is not 0, which indicates that the number is negative, the Calendar control displays in the system colors, as defined in the user's Windows Control Panel. Microsoft Windows provides a set of negative numbers that correspond to various parts of an application's window, such as the window frame or the title bar. You can set the BackColor property to one of these numbers, and the Calendar control will be displayed in the color you've selected.


Day Property

You can use the Day property to set the current day of the month in the Calendar control.

Setting

The setting for the Day property is an Integer data type value representing the day of the month.  Possible values range from 1 to 31 depending on the month and year.


DayFont Property

You can use the DayFont property to specify the characteristics of the font used when displaying the days of the week in the Calendar control.

Syntax

controlname.DayFont [ = name ]

controlname.DayFont.Name [ = name ]

controlname.DayFont.Size [ = size ]

controlname.DayFont.Bold [ = bold ]

controlname.DayFont.Italic [ = italic ]

controlname.DayFont.Underline [ = underline ]

controlname.DayFont.Strikethrough [ = strikethrough ]

Setting

The DayFont property uses the following settings.

Setting	Visual Basic
controlname	The name of the Calendar control object.
name	A string expression representing the font name.
Size	An Integer value that specifies the font size.
bold	A Boolean value that indicates whether the font is boldface.
italic	A Boolean value that indicates whether the font is in italic.
underline	A Boolean value that indicates whether the font is underlined.
strikethrough	A Boolean expression that indicates whether to use a strikethrough font.
Remarks

The DayFont property returns an object which has additional properties, the Name, Size, Bold, Italic, Underline, and Strikethrough properties.  You can use the DayFont property to set any of these properties for the days of the week displayed in the Calendar control.

Note	In order to use the properties of the object returned by the DayFont property, you must set a reference to the Standard OLE Types library.  To set a reference to this type library, click the Tools menu and choose References.

The default property for the object returned by the DayFont property is the Name property.  Therefore, you can set the DayFont property to a string specifying the name of a font, without explicitly referring to the Name property.


DayFont, GridFont Property Example

The following example sets properties of a Calendar control on a form when the form loads.  To try this example, add a calendar control named ActiveXCtl0 to a form, and paste the following code into the form's module.

Private Sub Form_Load()

Dim cal As Control

Set cal = Me!ActiveXCtl0

' Set font properties for days of week.

With cal.DayFont

.Name = "Arial"

.Size = 10

.Bold = True

.Italic = True

End With

' Set font properties for days of month.

With cal.GridFont

.Name = "Times New Roman"

.Size = 12

.Bold = False

.Italic = True

End With

End Sub


DayFontColor Property

You can use the DayFontColor property to specify the color used to display the days of the week in the Calendar control.

Setting

The setting for the DayFontColor property is a  Long value that represents an RGB color.

Remarks

The days of the week are displayed in the first row of the Calendar control, below the month/year title.

You can specify an RGB color for the DayFontColor property using the Visual Basic RGB function. The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower three bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).

If the high byte is not 0, which indicates that the number is negative, the Calendar control displays in the system colors, as defined in the user's Windows Control Panel. Microsoft Windows provides a set of negative numbers that correspond to various parts of an application's window, such as the window frame or the title bar. You can set the DayFontColor property to one of these numbers, and the day font will display in the color you've selected.


DayLength Property

You can use the DayLength property to determine whether the days of the week in the Calendar control are displayed in short, medium, or long format.

Setting

The DayLength property uses the following settings.

Setting	Description	Visual Basic
Short	Displays S, M, T, W, T, F, S	0
Medium	Displays Sun, Mon, Tue, Wed, Thu, Fri, Sat	1
Long	Displays Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday	2
Remarks

The days of the week are displayed in the first row of the Calendar control, below the month/year title.


FirstDay Property

You can use the FirstDay property to determine the first day of the week, as displayed in the first column of the Calendar control.

Setting

The setting for the FirstDay property is an integer that corresponds to a day of the week, as shown in the following table.

Setting	Visual Basic
Sunday	1
Monday	2
Tuesday	3
Wednesday	4
Thursday	5
Friday	6
Saturday	7
Remarks

The setting for the FirstDay property determines the date displayed in the first column of the Calendar control. The days of the week are displayed in the first row of the Calendar control, below the month/year title.


GridFont Property

You can use the GridFont property to specify the font used when displaying the days of the month in the grid of the Calendar control.

Syntax

controlname.GridFont [ = name ]

controlname.GridFont.Name [ = name ]

controlname.GridFont.Size [ = size ]

controlname.GridFont.Bold [ = bold ]

controlname.GridFont.Italic [ = italic ]

controlname.GridFont.Underline [ = underline ]

controlname.GridFont.Strikethrough [ = strikethrough ]

Setting

The GridFont property uses the following settings.

Setting	Visual Basic
name	A string expression indicating the font name.
size	An Integer value specifying the font size.
bold	A Boolean value that specifies whether the font is in boldface.
italic	A Boolean value that specifies whether the font is in italic.
underline	A Boolean value that specifies whether the font is underlined.
strikethrough	A Boolean expression that indicates whether to use a strikethrough font.
Remarks

The GridFont property returns an object which has additional properties, the Name, Size, Bold, Italic, Underline, and Strikethrough properties.  You can use the GridFont property to set any of these properties for the days of the month displayed in the Calendar control.

Note	In order to use the properties of the object returned by the GridFont property, you must set a reference to the Standard OLE Types library.  To set a reference to this type library, click the Tools menu and choose References.

The default property for the object returned by the GridFont property is the Name property.  Therefore, you can set the GridFont property to a string specifying the name of a font, without explicitly referring to the Name property.


GridFontColor Property

You can use the GridFontColor property to specify the color used when displaying the days of the month in the grid of the Calendar control.

Setting

The setting for the GridFontColor property is a Long value that represents an RGB color.

Remarks

You can specify an RGB color for the GridFontColor property using the Visual Basic RGB function. The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower three bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).

If the high byte is not 0, which indicates that the number is negative, the Calendar control displays in the system colors, as defined in the user's Windows Control Panel. Microsoft Windows provides a set of negative numbers that correspond to various parts of an application's window, such as the window frame or the title bar. You can set the GridFontColor property to one of these numbers, and the Calendar control grid font will display in the color you've selected.


GridLinesColor Property

You can use the GridLinesColor property to specify the color used to display the lines in the grid of a Calendar control.

Setting

The setting for the GridLinesColor property is a Long value that represents an RGB color.

Before setting the GridLinesColor property, make sure that the GridCellEffect property is set to Flat (0).  If the GridCellEffect property is not set to Flat, setting the GridLinesColor property has no effect.

Remarks

You can specify an RGB color for the GridLinesColor property using the Visual Basic RGB function. The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower three bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).

If the high byte is not 0, which indicates that the number is negative, the Calendar control displays in the system colors, as defined in the user's Windows Control Panel. Microsoft Windows provides a set of negative numbers that correspond to various parts of an application's window, such as the window frame or the title bar. You can set the GridLinesColor property to one of these numbers, and the Calendar control grid will display in the color you've selected.


GridCellEffect Property

You can use the GridCellEffect property to specify the effect used to display the grid of the Calendar control.

Setting

The GridCellEffect property uses the following settings.

Setting	Visual Basic
Flat	0
Raised	1
Sunken	2
Remarks

When the GridCellEffect property is set to Flat, you can also set the GridLinesColor, ShowHorizontalGrid, and ShowVerticalGrid properties.


Month Property

You can use the Month property to specify the month to display in the Calendar control.

Setting

The Month property uses the following settings.

Setting	Visual Basic
January	1
February	2
March	3
April	4
May	5
June	6
July	7
August	8
September	9
October	10
November	11
December	12
Remarks

If you change the value of the Month property, the values of the Year and Day properties remain the same if possible. If the current day is beyond the last day of the new month, the day changes to the last day of the new month.


MonthLength Property

You can use the MonthLength property to specify whether months are displayed in short or long format in the month/year title in the Calendar control.

Setting

The MonthLength property uses the following setting.

Setting	Description	Visual Basic
Short	Displays Jan, Feb, Mar, and so on.	0
Long	Displays January, February, March, and so on.	2
Remarks

The month/year title is displayed at the top of the Calendar control, above the days of the week, and to the left of the month dropdown box.


ShowDateSelectors Property

You can use the ShowDateSelectors property to specify whether to display the date selector dropdowns for month and year in the Calendar control.

Setting

The setting for the ShowDateSelectors property is a Boolean value (True or False).  If the ShowDateSelectors property is set to True, the date selector dropdowns appear in the upper right hand corner of the Calendar control.

Remarks

Without the date selectors, you can still set the month and year using the PreviousMonth, NextMonth, PreviousYear, and NextYear methods and their corresponding keyboard equivalents.

The date selectors are never printed with the Calendar control, regardless of the ShowDateSelectors setting.


ShowDays Property

You can use the ShowDays property to specify whether the days of the week are displayed in the Calendar control.

Setting

The setting for the ShowDays property is a Boolean value.  If the ShowDays property is set to True, the Calendar control displays the days of the week.

Remarks

The days of the week are displayed in the first row of the Calendar control, below the month/year title.


ShowHorizontalGrid Property

You can use the ShowHorizontalGrid property to specify whether horizontal gridlines are displayed in a Calendar control.

Setting

The setting for the ShowHorizontalGrid property is a Boolean value.

If the ShowHorizontalGrid property is set to True and the GridCellEffect property is set to Flat (0), the Calendar control displays horizontal gridlines.  If the GridCellEffect property is not set to Flat, setting the ShowHorizontalGrid property has no effect.


ShowTitle Property

You can use the ShowTitle property to specify whether the month/year title is displayed above the calendar grid.

Setting

The setting for the ShowTitle property is a Boolean value.  If the ShowTitle property is set to True, the Calendar control displays the month/year title.

Remarks

The month/year title is displayed at the top of the Calendar control, above the days of the week, and to the left of the month date selector.  If the ShowDateSelectors property is set to False, the month/year title is centered above the grid.


ShowVerticalGrid Property

You can use the ShowVerticalGrid property to specify whether vertical gridlines are displayed in a Calendar control.

Setting

The setting for the ShowVerticalGrid property is a Boolean value.

If the ShowVerticalGrid property is set to True and the GridCellEffect property is set to Flat (0), the Calendar control displays vertical gridlines.  If the GridCellEffect property is not set to Flat, setting the ShowVerticalGrid property has no effect.


TitleFont Property

You can use the TitleFont property to specify characteristics of the font displayed in the month/year title above the calendar grid.

Syntax

controlname.TitleFont [ = name ]

controlname.TitleFont.Name [ = name ]

controlname.TitleFont.Size [ = size ]

controlname.TitleFont.Bold [ = bold ]

controlname.TitleFont.Italic [ = italic ]

controlname.TitleFont.Underline [ = underline ]

controlname.TitleFont.Strikethrough [ = strikethrough ]

Setting

The TitleFont property uses the following settings.

Setting	Visual Basic
controlname	The name of the Calendar control object.
name	A string expression representing the font name.
Size	An Integer value that specifies the font size.
bold	A Boolean value that indicates whether the font is boldface.
italic	A Boolean value that indicates whether the font is in italic.
underline	A Boolean value that indicates whether the font is underlined.
strikethrough	A Boolean expression that indicates whether to use a strikethrough font.
Remarks

The month/year title is displayed at the top of the Calendar control, above the days of the week, and next to the month combo box.

The TitleFont property returns an object which has additional properties, the Name, Size, Bold, Italic, Underline, and Strikethrough properties.  You can use the TitleFont property to set any of these properties for the days of the week displayed in the Calendar control.

Note	In order to use the properties of the object returned by the TitleFont property, you must set a reference to the Standard OLE Types library.  To set a reference to this type library, click the Tools menu and choose References.

The default property for the object returned by the TitleFont property is the Name property.  Therefore, you can set the TitleFont property to a string specifying the name of a font, without explicitly referring to the Name property.


TitleFontColor Property

You can use the TitleFontColor property to specify the color of the font used to display the days of the week in the Calendar control.

Setting

The setting for the TitleFontColor property is a Long value that represents an RGB color.

Remarks

The month/year title is displayed at the top of the Calendar control, above the days of the week, and next to the month combo box.

You can specify an RGB color for the TitleFontColor property using the Visual Basic RGB function. The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower three bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).

If the high byte is not 0, which indicates that the number is negative, the Calendar control displays in the system colors, as defined in the user's Windows Control Panel. Microsoft Windows provides a set of negative numbers that correspond to various parts of an application's window, such as the window frame or the title bar. You can set the TitleFontColor property to one of these numbers, and the Calendar control title will display in the color you've selected.


Value Property (Calendar Control)

You can use the Value property to set or retrieve the current date in the Calendar control.

Setting

The setting for the Value property is a date value or Null.

Remarks

Valid dates for the Calendar control range from 1/1/1900 to 12/31/2100.

The Value property changes when you use the arrow keys, the mouse, or the date selector dropdowns to change the date.  If you set the Value property to Null, no date is highlighted.

You can bind the Calendar control to a field in the table or query underlying the form that contains the Calendar control.  This is useful if you want the Calendar control to display a date based on data in your application.

To bind the Calendar control to a field, set the Calendar control's ControlSource property to the name of the field.  The field must be a Date/Time field.

Once you've bound the Calendar control to a field, the Calendar control will display the value of that field for each record on the form.  Additionally, setting the Value property of the Calendar control sets the value of the field in the underlying table.


ValueIsNull Property (Calendar Control)

You can use the ValueIsNull property to specify whether to highlight the current date on the Calendar control.

Setting

The setting for the ValueIsNull property is a Boolean value.  If the ValueIsNull property is set to True, the current date on the Calendar control is highlighted.

By default the ValueIsNull property is set to False.

Remarks

When you set the ValueIsNull property to True, the Calendar control remembers the current date. If you set the ValueIsNull property back to False, the current date is highlighted again.

Setting the Value property directly or using the arrow keys, the mouse, or the date selector dropdown boxes to select a date automatically sets the ValueIsNull property to False.  If you don't want the user to change the setting of this property, set the control's Enabled property to False.  ???Need to test this???


Year Property

You can use the Year property to specify the year displayed in the Calendar control.

Setting

The setting for the Year property is an Integer value between 1900 and 2100.


AboutBox Method

You can use the AboutBox method to display an informational dialog box about the Calendar control, including its version and copyright information.

Syntax

controlname.AboutBox

The AboutBox method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.


NextDay Method

You can use the NextDay method to increment the value of a Calendar control by one day.

Syntax

controlname.NextDay

The NextDay method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

If you apply the NextDay method when the value of the calendar control is the last day of a month or year, the month or the year is incremented.  The value of the Calendar control is the date that is currently selected in the control.  This value is stored in the control's Value property.

Pressing the RIGHT ARROW key on the keyboard when the Calendar control has the focus is identical to executing the NextDay method.


NextDay Method Example

The following example increments the value of a Calendar control by one day when the user clicks the button named ShowNextDay.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowNextDay.  Paste the following code into the form's module.  Switch to Form view and click the command button to increment the date.

Private Sub ShowNextDay_Click()

Me!ActiveXCtl0.NextDay

End Sub


NextMonth Method

You can use the NextMonth method to increment the value of a Calendar control by one month.

Syntax

controlname.NextMonth

The NextMonth method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

If you apply the NextMonth method when the current month is December, the year is also incremented.

Pressing the RIGHT ARROW key while holding down the CTRL key on the keyboard is identical to executing this method.


NextMonth Method Example

The following example increments the value of a Calendar control by one month when the user clicks the button named ShowNextMonth.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowNextMonth.  Paste the following code into the form's module. Switch to Form view and click the command button to increment the month.

Private Sub ShowNextMonth_Click()

Me!ActiveXCtl0.NextMonth

End Sub


NextWeek Method

You can use the NextWeek method to increment the value of a Calendar control by one week.

Syntax

controlname.NextWeek

The NextWeek method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the DOWN ARROW key on the keyboard is identical to executing this method.


NextWeek Method Example

The following example increments the value of a Calendar control by one week when the user clicks the button named ShowNextWeek.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowNextWeek.  Paste the following code into the form's module. Switch to Form view and click the command button to increment the week.

Private Sub ShowNextWeek_Click()

Me!ActiveXCtl0.NextWeek

End Sub


NextYear Method

You can use the NextYear method to increment the value of a Calendar control by one year.

Syntax

controlname.NextYear

The NextYear method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the DOWN ARROW key while holding down the CTRL key on the keyboard is identical to executing this method.


NextYear Method Example

The following example increments the value of a Calendar control by one year when the user clicks the button named ShowNextYear.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowNextYear.  Paste the following code into the form's module. Switch to Form view and click the command button to increment the year.

Private Sub ShowNextYear_Click()

Me!ActiveXCtl0.NextYear

End Sub


PreviousDay Method

You can use the PreviousDay method to decrement the value of a Calendar control by one day.

Syntax

controlname.PreviousDay

The PreviousDay method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the LEFT ARROW key on the keyboard is identical to executing this method.


PreviousDay Method Example

The following example decrements the value of a Calendar control by one day when the user clicks the button named ShowPreviousDay.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowPreviousDay.  Paste the following code into the form's module. Switch to Form view and click the command button to decrement the date.

Private Sub ShowPreviousDay_Click()

Me!ActiveXCtl0.PreviousDay

End Sub


PreviousMonth Method

You can use the PreviousMonth method to decrement the value of a Calendar control by one month.

Syntax

controlname.PreviousMonth

The PreviousMonth method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the LEFT ARROW key while holding down the CTRL key on the keyboard is identical to executing this method.


PreviousMonth Method Example

The following example decrements the value of a Calendar control by one month when the user clicks the button named ShowPreviousMonth.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowPreviousMonth.  Paste the following code into the form's module. Switch to Form view and click the command button to decrement the month.

Private Sub ShowPreviousMonth_Click()

Me!ActiveXCtl0.PreviousMonth

End Sub


PreviousWeek Method

You can use the PreviousWeek method to decrement the value of a Calendar control by one week.

Syntax

controlname.PreviousWeek

The PreviousWeek method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the UP ARROW key on the keyboard is identical to executing this method.


PreviousWeek Method Example

The following example decrements the value of a Calendar control by one week when the user clicks the button named ShowPreviousWeek.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowPreviousWeek.  Paste the following code into the form's module. Switch to Form view and click the command button to decrement the week.

Private Sub ShowPreviousWeek_Click()

Me!ActiveXCtl0.PreviousWeek

End Sub


PreviousYear Method

You can use the PreviousYear method to decrement the value of a Calendar control by one year.

Syntax

controlname.PreviousYear

The PreviousYear method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing the UP ARROW key while holding down the CTRL key on the keyboard is identical to executing this method.


PreviousYear Method Example

The following example decrements the value of a Calendar control by one year when the user clicks the button named ShowPreviousYear.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a command button named ShowPreviousYear.  Paste the following code into the form's module. Switch to Form view and click the command button to decrement the year.

Private Sub ShowPreviousYear_Click()

Me!ActiveXCtl0.PreviousYear

End Sub


Refresh Method (Calendar Control)

You can use the Refresh method to repaint the Calendar control.

Syntax

controlname.Refresh

The Refresh method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.


Refresh Method, FirstDay Property Example

This example enables the user to select the first day to display in a Calendar control.  The user selects either Sunday or Monday from a combo box, and the calendar is updated and refreshed.

To try this example, create a form with a Calendar control named ActiveXCtl0 and a combo box named Combo1.  Paste the following code into the form's module.  Switch to Form view and change the selection in the combo box.

' Initialize combo box.

Private Sub Form_Load()

Dim cbo As ComboBox

Set cbo = Me!Combo1

' Specify type of source of values.

cbo.RowSourceType = "Value List"

' Specify values.

cbo.RowSource = "Sunday;Monday"

End Sub

Private Sub Combo1_AfterUpdate()

Dim ctl As Control

Set ctl = Me!ActiveXCtl0

'Set FirstDay property based on selection in combo box.

If Combo1 = "Sunday" Then

' Specify Sunday as first day.

ctl.FirstDay = 1

Else

' Specify Monday as first day.

ctl.FirstDay = 2

End If

' Refresh Calendar control.

ctl.Refresh

End Sub


Today Method

You can use the Today method to set the value of the Calendar control to today's date.

Syntax

controlname.Today

The Today method uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Pressing CTRL+T on the keyboard is identical to running this method.


AfterUpdate Event (Calendar Control)

The AfterUpdate event occurs after the user selects a new date in the Calendar control and the new date is highlighted.

Syntax

Sub controlname_AfterUpdate( )

The AfterUpdate event procedure uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

This event occurs whenever the user moves to a new date in the Calendar control, using the keyboard keys or the mouse.

The Value property of the Calendar control changes to the new date before the AfterUpdate event occurs.


BeforeUpdate Event (Calendar Control)

The BeforeUpdate event occurs after the user selects a new date in the Calendar control but before the new date is highlighted.

Syntax

Sub controlname_BeforeUpdate (Cancel as Integer)

The BeforeUpdate event procedure uses the following arguments.

Argument	Description
controlname	The name of the Calendar control object.
Cancel	If set to True (-1) within the event procedure, the event is cancelled.
Remarks

This event occurs whenever the user moves to a new date in the Calendar control, using the keyboard keys or the mouse.

The Value property of the Calendar control changes to the new date before the BeforeUpdate event occurs.

If the user's input is limited to a range of dates and their selection falls outside of that range, the BeforeUpdate event procedure can be used to cancel the calendar update. To cancel the event, set Cancel to True within the event procedure.

When Cancel is set to True, the new date selected by the user is not highlighted.  Once the event procedure has finished running, the Value property is reset to the value it had before the BeforeUpdate event procedure ran.


Click Event (Calendar Control)

The Click event occurs when the user clicks on a date in the Calendar control.

Syntax

Sub controlname_Click()

The Click event procedure uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Clicking on a date sets the Calendar control's Value property to that date.


DblClick Event (Calendar Control)

The DblClick event occurs when the user double-clicks on a date in the Calendar control.

Syntax

Sub controlname_DblClick()

The DblClick event procedure uses the following argument.

Argument	Description
controlname	The name of the Calendar control object.
Remarks

Once the user has double-clicked on a date, the application can retrieve that date with the Value property.

The Click event always occurs immediately before the DblClick event occurs.  The BeforeUpdate and AfterUpdate events occur before the Click or DblClick events occur.


KeyDown, KeyUp Events (Calendar Control)

The KeyDown and KeyUp events occur when the user presses or releases a key while the Calendar control has the focus.

Syntax

Sub controlname_KeyDown (KeyCode As Integer, ByVal Shift As Integer)

Sub controlname_KeyUp (KeyCode As Integer, ByVal Shift As Integer)

The KeyDown and KeyUp event procedures use the following arguments.

Argument	Description
controlname	The name of the Calendar control object.
KeyCode	An integer that is a key code value.  To see a list of possible values, open the Object Browser, select VBA in the Project/Library box, and open the KeyCodeConstants module in the Classes list.
Shift	A value specifying the state of the SHIFT, CTRL, and ALT keys. The following values are possible for the Shift argument:
	Key Pressed	Value of Shift
	None	0
	SHIFT	1
	CTRL	2
	ALT	4
	SHIFT-CTRL	3
	SHIFT-ALT	5
	CTRL-ALT	6
	SHIFT-CTRL-ALT	7
Remarks

You can use the KeyDown and KeyUp events to determine which key or combination of keys has been pressed.  Within the KeyDown or KeyUp event procedure, check the value of the KeyCode argument to determine which key was pressed.  Check the value of the Shift argument to determine whether the SHIFT, CTRL, or ALT key was pressed simultaneously.


KeyPress Event (Calendar Control)

The KeyPress event occurs when the user presses and releases an ANSI key while the Calendar control has the focus.

Syntax

Sub controlname_KeyPress (KeyAscii As Integer)

The KeyPress event procedure uses the following arguments.

Argument	Description
controlname	The name of the Calendar control object.
KeyAscii	An integer that is a numeric ANSI key code.
Remarks

You can use the KeyPress event to determine which alphanumeric key the user has pressed.  Within the KeyPress event procedure, check the value of the KeyAscii argument.

To return the alphanumeric character represented by the KeyAscii argument, use the Visual Basic Chr function.


NewMonth Event

The NewMonth event occurs whenever the value of the Calendar control changes to display a different month.

Syntax

Sub controlname_NewMonth

The NewMonth event procedure uses the following arguments.

Argument	Description
controlname	The name of the Calendar control object.


NewYear Event

The NewYear event occurs whenever the value of the Calendar control changes to display a different year.

Syntax

Sub controlname_NewYear

The NewYear event procedure uses the following arguments.

Argument	Description
controlname	The name of the Calendar control object.