ACC: How to Create a Pop-Up Calendar Control on a Form
ID: Q190194
|
The information in this article applies to:
-
Microsoft Access versions 7.0, 97
Moderate: Requires basic macro, coding, and interoperability skills.
SUMMARY
When you want to have a user enter a date value on a form, you can improve
usability of the form by providing a Calendar control on the form. To
reduce clutter on the form, you can simulate a feature of Microsoft Outlook
by having the calendar pop up when the user clicks a button. This article
describes how to create a pop-up calendar by using a combo box and the
Calendar control (mscal.ocx).
MORE INFORMATION
Creating a Pop-Up Calendar
- Open the sample database Northwind.mdb.
- Create a new form based on the Orders table and save it as
frmOrderDateForm.
- Add a combo box to the form and set the ControlSource property of the
combo box to the OrderDate field.
- Insert the Calendar control on the form.
NOTE: To insert a Calendar control, click ActiveX Control on the Insert menu, and then select either Calendar Control or Calendar Control 8.0 depending on your version of Access, 7.0 or 97.
- Set the following properties for the Calendar control:
Name: Calendar
Visible: No
- Add the following code to the MouseDown event of the OrderDate
combo box:
Private Sub OrderDate_MouseDown(Button As Integer, _
Shift As Integer, X As Single, _
Y As Single)
' Show Calendar and set its date.
Calendar.Visible = True
Calendar.SetFocus
' Set to today if OrderDate has no value.
Calendar.Value = IIf(IsNull(OrderDate), Date, OrderDate.Value)
End Sub
- Add the following code to the Click event of the Calendar control.
NOTE: You will have to open up one of the listed events and then change
that event to the Click event.
Private Sub Calendar_Click()
' Set OrderDate to the selected date and hide the calendar.
OrderDate.Value = Calendar.Value
OrderDate.SetFocus
Calendar.Visible = False
End Sub
- Save the form and switch to Form View.
You will find that when you click the arrow in the OrderDate box, the
Calendar control will be made visible and will be set to the date in the
box. After you select a date from the calendar, the calendar will disappear
and the selected date will now be in the box. If the OrderDate box has no
value, the calendar will show the current date.
Additional Example
If you are using Access 97, you can see an additional example of using the
Calendar control as well as other ActiveX controls in the Microsoft Access
97 ActiveX Control Samples database. The database is distributed on the
Office 97 Developer Edition (ODE) CD in the following directory:
CD-DRIVE:\MSDS\ODESMPL\ODE\OLECONT\Actctrls.mdb
If you don't have the ODE, you can download this database from Microsoft's
Support Web site at the following address:
http://support.microsoft.com/download/support/mslfiles/ACTXSAMP.EXE
REFERENCES
For more information about the Calendar control, search the Help Index for
"Calendar Control."
Additional query words:
Keywords : kbdta AccCon FmrHowto IntpCstm KbVBA
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto