You can use ActiveX controls in many places in your own applications. Use your imagination to determine where controls will enhance your application's usefulness. The following examples illustrate a few potential uses of ActiveX controls.
One example of an ActiveX control is in the frmReportDateRange dialog box, shown in Figure 21.25. You can use the Calendar control to populate the Beginning Date and Ending Date text boxes.
The code for adding the Calendar control looks like this:
Private Sub cmdSetDates_Click() On Error GoTo cmdSetDates_Error If cmdSetDates.Caption = "Set Beginning Date" Then BeginDate = calSetDates.Value cmdSetDates.Caption = "Set Ending Date" Else EndDate = calSetDates.Value cmdSetDates.Caption = "Set Beginning Date" End If Exit Sub cmdSetDates_Error: MsgBox "Error # " & Err.Number & ": " & Err.Description Exit Sub End Sub
Because the same calendar is used to populate the Beginning Date and Ending Date text boxes, the form has a command button with a caption that toggles. The user can select a date, and then click Set Beginning Date. The BeginDate text box is populated with the value selected on the calendar, and the command button's caption is set to display Set Ending Date. If the command button's caption says Set Ending Date and the user clicks that button, the EndDate text box is filled with the value selected on the calendar, and the command button's caption changes to say Set Beginning Date.