Microsoft KB Archive/190194

= ACC: How to Create a Pop-Up Calendar Control on a Form =

Article ID: 190194

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q190194



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).



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 </li>  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 </li> Save the form and switch to Form View.</li></ol>

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: <pre class="fixed_text">  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://download.microsoft.com/download/access97/sample/1/WIN98/EN-US/Actxsamp.exe

<div class="references_section">