Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Using the Calendar Control


The Calendar control is one of the more powerful OCX controls available. Understanding its properties and methods makes it a lot easier to work with; they are covered in the following sections. Most of the examples are found in frmCalPropsAndMethods.

Properties of a Calendar Control


The Day, Month, and Year properties designate the day, month, and year displayed on the calendar. These properties are automatically changed at runtime as the user selects different dates on the calendar. You can modify the values programmatically by using macros or Visual Basic, thereby changing the day, month, or year that's selected.

The Value property is one of the Calendar control's most important properties. It retrieves the selected calendar date or moves the date highlight to a specific day. The following code uses the Value property to display the selected day in a message box:

Private Sub cmdDisplayDate_Click()
'Display the date selected on the calendar
MsgBox calSelectADay.Value
End Sub

The ValueIsNull property lets you indicate that no date is selected on the calendar. This property is used when you want to make sure that the user explicitly selects a date.

The DayFont and DayFontColor properties specify the font and color for displaying the day titles. The DayFont property is further broken down into the properties Name, Size, Bold, Italic, Underline, and Strikethrough. You can modify an individual property like this:

calSelectADay.DayFont.Italic = True

This code modifies the Italic property of the DayFont property of the Calendar control, setting it to True.

You can use the With…End With construct to change several font properties at once:

With calSelectADay.DayFont
.Bold = True
.Italic = True
.Name = "Arial"
End With

This code modifies three attributes of the DayFont property of the Calendar control. It sets the Bold property to True, the Italic property to True, and the Name property to Arial.

You can use the DayFontColor property to easily modify the color of the day titles:

calSelectADay.DayFontColor = 16711680

This code changes the DayFontColor property of the Calendar control to blue.

The GridFont and GridFontColor properties are similar to the DayFont and DayFontColor properties. GridFont determines the font type and size attributes for the text in the calendar, and GridFontColor indicates the text color in the calendar. For example, the following routine modifies the Bold, Italic, and Name properties of the GridFont property and changes the color of the days displayed on the calendar to magenta:

Private Sub cmdChangeGridFont_Click()
'Change attributes of the font on the grid
With calSelectADay.GridFont
.Bold = True
.Italic = True
.Name = "Arial"
End With
calSelectADay.GridFontColor = 8388736 'Magenta
End Sub

The DayLength and MonthLength properties designate how you want the day or month titles to be displayed. The available choices for DayLength are Short (0), Medium (1), and Long (2). Short displays the day as one character, Medium displays the day as a three-character abbreviation, and Long displays the full day (for example, Monday). The available choices for MonthLength are Short (0) and Long (2). Short displays the month as a three-character abbreviation, and Long displays the full month name. The following code specifies both the DayLength and MonthLength properties as Short:

Private Sub cmdChangeLength_Click()
'Modify the display of the day and month titles
calSelectADay.DayLength = 0
calSelectADay.MonthLength = 0
End Sub

The ShowDateSelectors property indicates whether combo boxes appear at the top of the calendar, allowing the user to select a month and year. This property can be set to True or False.

The ShowTitle property indicates whether the month and year are displayed at the top of the calendar.

The GridLinesFormat and GridLinesColor properties specify whether the gridlines are raised, sunken, or flat, and what color they are.

Methods of a Calendar Control


The Calendar control also has several methods, or actions you can take on the Calendar object. The NextDay, PreviousDay, NextWeek, PreviousWeek, NextMonth, PreviousMonth, NextYear, and PreviousYear methods all move the control's Value property forward or backward by the specified period of time.

Other methods of the Calendar control include the following:

  • The Refresh method repaints the Calendar control.

  • The Today method sets the Value property to the current date.

  • The AboutBox method displays the Calendar control's About box.


NOTE

The following examples require controls supplied with Microsoft Office Developer 2002. You must have MOD 2002 for the following code samples to run. Also, if you have MOD, you can distribute these tools royalty-free to your users.

If you have MOD installed and still can't run some of the examples, you might want to check the References dialog box to make sure that the controls are properly referenced.

Figure 21.11 shows how the native Access Calendar control works. As you can see, the form, called frmCalendar, lets the user move from day to day, month to month, or year to year. The user can also move to the current day, or even select a date, and then click the Display Orders for Selected Date command button to view all the orders placed on the selected date.

Figure 21.11. An example of using the Calendar control.


The code for the Today command button illustrates using the Today method:

Private Sub cmdToday_Click()
'Change the selected date in the calendar control
'to today's date
calPickADay.Today
End Sub

Because the Today method is issued on the Calendar control, the selected day will become the current date. The code for the Display Orders for Selected Date command button looks like this:

Private Sub cmdOrders_Click()
'Change the recordsource of the form
'to select only those rows where the order
'date matches the data selected in the
'calendar control
frmOrdersByDate.Form.RecordSource = _
"Select * from qryOrdersByDate Where OrderDate = #" _
& calPickADay.Value & "#"
End Sub

This code changes the subform's RecordSource to include only those records in which the OrderDate is equal to the selected calendar date. The remainder of the code for the frmCalendar form is discussed in the following section.


/ 544