Introduction
In an earlier article, Animated Floating Calendar, we learned how to use the Calendar Control to simplify date entry form fields. In that method, a single calendar control was used for multiple date fields by automatically moving it near the selected field with a smooth unfolding animation.
This approach helps to save space on the Form; otherwise, we would need to place separate calendar controls for each date field.
Now, we have an even better alternative — the Microsoft Date and Time Picker (DTPicker), an ActiveX control that closely resembles a Combo Box and is extremely easy to use.
Learn its Simple Usage.
Let us try a simple example to learn how to use this Calendar for a Date Field on a Form.
Import the following Objects from C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb sample database:
- Table: Employees
- Form: Employees
Open the Employees Form in Design View.
Select the Company Info Tab.
Select the ActiveX Control option from the Insert Menu.
Select the Microsoft Date and Timer Picker Control from the displayed list and click OK to create a control on the Form.
Move the control near the HireDate Field and resize it as shown in the sample design of the Form given below:
Few Simple Rules of Date/Time Picker Control.
Before using the Date and Time Picker control with date fields, it’s important to understand a few simple rules.
You can set the Control Source property of the Date and Time Picker to a field, such as HireDate, and remove the existing HireDate text box from the form.
However, note that the HireDate field cannot be blank. If you navigate to a record where the HireDate field is empty, or if you try to add a new record without assigning a date, the control will display the following error message:
“Can’t set the value to NULL when CheckBox property = FALSE.”
This error message indicates that the HireDate field cannot be left blank, and you also cannot clear the date value from the field once it has been set—unless the CheckBox property of the Date and Time Picker control is set to Yes.
Important Settings.
First things first—make sure the Date and Time Picker control you added to the form is selected. Then, open the Property Sheet (by choosing View → Properties or pressing Alt + Enter) and make the following changes:
-
Set the Control Source property to HireDate.
-
Set the CheckBox property to Yes.
When you navigate to a record, the Date and Time Picker will automatically display the date stored in the HireDate field. To change the existing hire date, simply move the calendar to the desired year and month, then click the required date.
If you move to a record where the HireDate field is NULL, the check mark will disappear, and the field will appear disabled, indicating that it’s empty. However, the control may still display the date from the previously accessed record. If you open the calendar drop-down, that previous date will automatically populate the HireDate field. You can either remove the check mark to clear the field or select a new date from the calendar to overwrite the value.
If you prefer to adjust the date manually—by incrementing or decrementing the day, month, or year like you would on a digital clock—set the UpDown property to Yes. This changes the calendar’s drop-down into a spin button control, replacing the standard calendar view.
Once enabled, click any date segment (day, month, or year), and use the spin buttons to increase /decrease the value to your desired setting.
-
You can experiment with the Date and Time Picker control, keeping the points mentioned above, to better understand how the calendar behaves under different settings.
Settings for Time Value.
If you want to enter time values instead of dates using the Date and Time Picker control, change its Format property value to 2. This automatically sets the UpDown property to Yes, replacing the drop-down calendar with a spin button control. You can then use the spin buttons to adjust each segment of the time value — hours (hh), minutes (mm), seconds (ss), and AM/PM — individually, just as explained earlier.
tanks for u
ReplyDelete[...] Office toolbars, ribbons, task panes on RO Chrome - Add-in Express Blogs LEARN MS-ACCESS TIPS AND TRICKS - Microsoft Date Time Picker Control LEARN MS-ACCESS TIPS AND TRICKS - Keyboard Shortcuts LEARN MS-ACCESS TIPS AND TRICKS - Database [...]
ReplyDelete[...] You should know few things about Date/time Picker control, take a look at the following link: http://www.msaccesstips.com/2010/02/...icker-control/ [...]
ReplyDelete[…] does appear to be one in Access 2010. http://msaccesstips.com/2010/02/micr...icker-control/ Reply With […]
ReplyDelete