HOWTO: Use the Calendar Control to Enter and Display Dates
ID: Q158248
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, version 5.0
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
- Place a text box on the form and set the Control Source to Order_ID
- Place three command buttons on the form.
- 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
- 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
- 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
- Save and run the form.
REFERENCES
Visual FoxPro 5.0 Help; search on: "Calendar Control"
Additional query words:
Keywords : kbinterop kbVFp500
Version :
Platform :
Issue type : kbhowto