Microsoft KB Archive/158248

= HOWTO: Use the Calendar Control to Enter and Display Dates =

Article ID: 158248

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition

-



This article was previously published under Q158248



SUMMARY
The Calendar Control is an ActiveX Control that ships with Visual FoxPro 5.0. You can use the control to graphically show dates that are stored in a table. You can also use it as a data entry control by letting users click on the date they want to store into a date field.



MORE INFORMATION
The following example shows how a Calendar Control can be used to enter or view a date field in a table:

 Enter the following command in the Command window:

CREATE TABLE Test (Order_ID C(5), Order_Date D(8))

 Enter three records. Create a form and add the Test table to the DataEnvironment. Place an OLE Container Control on the form. Click Insert Control from the Insert Object dialog box. From the Control Type list, select Calendar Control and then click OK.  Add the following code to the Olecontrol1 Click Event: IF This.Object.Value < DATE ** Display a message if you try and enter a date earlier than ** the current date = MessageBox("Order Date must be today or later") ELSE ** Store the date they picked into the table REPLACE Order_Date WITH This.Value ThisForm.Refresh ENDIF </li> Place a text box on the form and set the Control Source to Order_ID</li> Place three command buttons on the form.</li>  Set the Caption of command1 to NEW and add the following code to the Click event: APPEND BLANK ThisForm.Olecontrol1.Object.Today ** Set the value of the Calendar Control to today's date ThisForm.Refresh </li>  Set the Caption of command2 to PREVIOUS and add the following code to the Click event: SKIP -1 IF BOF GO TOP ENDIF ThisForm.Olecontrol1.Object.Value = Order_Date ThisForm.Refresh </li>  Set the Caption of command3 to NEXT and add the following code to the Click event: SKIP IF EOF GO BOTTOM ENDIF ThisForm.Olecontrol1.Object.Value = Order_Date ThisForm.Refresh </li> Save and run the form.</li></ol>

<div class="references_section">