Online Book Reader

Home Category

Access Cookbook - Ken Getz [197]

By Root 2016 0
to non-default values to make the calendar look better at a smaller size. Use the Apply button to preview the settings while keeping the properties sheet open. You may also wish to use the Help button to view the custom control's help file at this time. (Not all custom controls support the Apply and Help buttons.) When you're done, click on the OK button to close the custom properties sheet. These special custom control properties are also available from the Other tab of the control's regular properties sheet.

Figure 9-31. The custom properties sheet for the Calendar control

Table 9-7. Custom property settings for the Calendar control

Tab

Property

Value

General

DayLength

Short

MonthLength

Short

Fonts

TitleFont

Font: MS Sans Serif; Font Style: Bold; Size: 9.65 points

Save the form and switch to form view to see it in action.

Create a generic unbound pop-up calendar form


Follow these steps to create a generic unbound pop-up calendar form:

Create a new form called frmPopupCal with the properties shown in Table 9-8.

Table 9-8. Property settings for the pop-up calendar form

Property

Value

DefaultView

Single Form

ScrollBars

Neither

RecordSelectors

No

NavigationButtons

No

AutoResize

Yes

PopUp

Yes

Modal

Yes

BorderStyle

Thin

MinMaxButtons

None

Select Insert → ActiveX Control. The Insert ActiveX Control dialog will appear, as shown in Figure 9-29. Select the Calendar control and click OK to close the dialog. Move and resize the control as needed. On the frmPopupCal form, we resized the control to a width of 2.4167" and a height of 1.9167". Name the control ocxCal.

Adjust the custom properties of the control as discussed in Step 4 of the previous section.

Add seven command button controls to the right of the control, as shown in Table 9-9.

Table 9-9. Command buttons for the pop-up calendar form

Control name

Caption

cmdToday

Goto Today

cmdPrevYear

<

cmdNextYear

>

cmdPrevMonth

<

cmdNextMonth

>

cmdOK

&OK

cmdCancel

&Cancel

Create an event procedure attached to the Click event of each button. (If you're unsure of how to do this, see How Do I Create an Event Procedure? in the the preface of this book.) Add the following event procedures to the appropriate buttons:

Private Sub cmdCancel_Click( )

DoCmd.Close acForm, Me.Name

End Sub

Private Sub cmdNextMonth_Click( )

Me.ocxCal.NextMonth

End Sub

Private Sub cmdNextYear_Click( )

Me.ocxCal.NextYear

End Sub

Private Sub cmdOK_Click( )

Me.Visible = False

End Sub

Private Sub cmdPrevMonth_Click( )

Me.ocxCal.PreviousMonth

End Sub

Private Sub cmdPrevYear_Click( )

Me.ocxCal.PreviousYear

End Sub

Private Sub cmdToday_Click( )

Me.ocxCal.Today

End Sub

Add the following code to the event procedure attached to the form's Load event:

Private Sub Form_Load( )

If Not IsNull(Me.OpenArgs) Then

Me.CalDate = Me.OpenArgs

End If

End Sub

Add the following code to the event procedure attached to the Calendar control's DblClick event:

Private Sub ocxCal_DblClick( )

Call cmdOK_Click

End Sub

Note that this event will be found under the Other tab of the control's properties sheet, not under the Event tab.

Add the following two property procedures to the form's module:

Public Property Let CalDate(datDate As Date)

Me.ocxCal = datDate

End Property

Public Property Get CalDate( ) As Date

CalDate = Me.ocxCal

End Property

Save and close frmPopupCal.

Import the basCalendar module from 09-09.MDB into your database.

Create a new form with a bound date text box control. This form will be used to test the pop-up calendar form created in Steps 1 through 10. Add a command button to the right of the text box control. Name it cmdPopupCal and add the following code to the event procedure attached to the command button's Click event:

Private Sub cmdPopupCal_Click( )

Dim ctlDate As TextBox

Dim varReturn As Variant

Set ctlDate = Me.txtApptDate

' Request the date.

varReturn = acbGetDate(ctlDate.Value)

' Change the

Return Main Page Previous Page Next Page

®Online Book Reader