We have learned how to use Calendar Control for easy entry of Date Values into Fields on Form through the earlier Article: Animated Floating Calendar. We have used a single Calendar Control for several Date Fields by moving the Calendar Control automatically near the selected Date Field with unfolding animation.

 

We have used this method to save space on the Form otherwise we need to place several Calendar Controls linked to each date field on the Form.

 

Now we have a better ActiveX Control . . . Microsoft Date Time Picker – a Calendar Control that almost looks like a Combo Box on Form and easy to use.

 

Let us get into a simple example to learn how to use this Calendar for a Date Field on a Form.

 

  1. Import the following Objects from C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb sample database:

     

    • Table: Employees
    • Form: Employees

     

  2. Open the Employees Form in Design View.
  3.  

  4. Select the Company Info Tab.
  5.  

  6. Select ActiveX Control. . . from Insert Menu.
  7.  

  8. Select Microsoft Date and Timer Picker Control from the displayed list and click OK to create a control on the Form.
  9.  

  10. Move the control near the HireDate Field and resize it as shown on the sample design of the Form given below:

     

     

    We must know few simple rules that go with this Control to use it with Date Fields.

     

    • We can set the Control Source Property of Date Time Picker to HireDate and remove the existing HireDate Field.
    •  

    • The HireDate field cannot be blank. When you make a record current with HireDate Field blank or attempt to add a new record the Date Time Picker will show an Error Message: Can’t set value to NULL when CheckBox Property=FALSE.
    •  

     

    The Error message indicates that HireDate field cannot be left blank or you cannot remove Date Value from a field and make it blank unless you set the CheckBox Property of the Date and Time Picker Control to Yes.

  11.  

  12. So, first thing first, ensure that the Date Time Picker Control you have added to the Form is in selected state or click to select it, display the Property Sheet (View – -> Properties or Alt+Enter) of the Calendar Control and change the Control Source Property Value to HireDate and change the CheckBox Property Value to Yes.

     

    • When you move to a particular record the Calendar will automatically move to the date earlier recorded in the HireDate Field. If you want to change the existing HireDate then move the Calendar to the desired Year and Month and click on the required date.
    •  

    • When you move to a record with HireDate Field value NULL the Check-Mark disappears and the HireDate field looks like disabled indicating that it is empty but the field shows the date value of last record accessed. If you click on the drop down control of the Calendar to open it then the date value, shown from last accessed record will be entered into the HireDate field immediately, whether you want it or not. You can remove the CheckMark to empty the field or select correct date from the Calendar to overwrite the wrong value.
    •  

    • If you prefer to set Date by incrementing or decrementing individual segment (day/month/year) of the Date value, like you do on a Digital Clock, then you may change the UpDown Property Value to Yes. This will change the Drop-down control of the Calendar to a Spin Button Control and the normal Calendar View will not be available.
    •  

    • You may click on the Day Segment of the Date value and use the Spin Button Control of the Date Time Picker to increase or decrease the value to the desired level. Use the same method for Month and Year Values.
    •  

  13. You may experiment with the Date Time Picker Control, keeping those points I have mentioned above, to understand the behavior of the Calendar control better.

     

     

  14. If you want to enter Time rather than Date into a field from the Date Time Picker then change the Format Property Value to 2. This will automatically change the UpDown Control to Yes and the Spin Button control appear in place of the drop-down control and these can be used to set each segment (hh:mm:ss AM/PM) of the Time Value individually as explained above for date.
  15.  

StumbleUpon Toolbar

 


Form Bookmarks and Data Editing-2

Form Bookmarks and Data Editing

Run Slide-show when Form is idle

Filter Function Output in ListBox-2

Filter Function Output in ListBox