The information in this article applies to:
- Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes how to create form controls that increment or
decrement a date. After a date control is initialized to the date stored
in the computer, command buttons are used to increment or decrement the
displayed date.
MORE INFORMATION
The following example demonstrates how to create controls on a form that
can be used to increment or decrement the displayed date:
- Create a new form not based on any table or query and name it Date
Selector.
- Add the following unbound text box for the date value:
Object: Text Box
----------------------
Name: Call Date
Format: General Date
Default Value: =Date()
Locked: Yes
SpecialEffect: Sunken
NOTE: The Name property is called the ControlName property in Microsoft
Access 1.0 and 1.1.
- Add the following command buttons to change the date value:
Object: Command Buttons
-----------------------
Name: Decrease
Caption: <
AutoRepeat: Yes
OnClick: Change Date
Name: Advance
Caption: >
AutoRepeat: Yes
OnClick: Change Date
NOTE: The OnClick property is called the OnPush property in versions
1.0 and 1.1.
- Create a macro to increase and decrease the date:
Macro Name Condition Action
----------------------------------------------------------------
Change Date Screen.ActiveControl.ControlName="Advance" SetValue
... GoToControl
... GoToControl
Screen.ActiveControl.ControlName="Decrease" SetValue
... GoToControl
... GoToControl
Change Date Actions
--------------------------------------------------
SetValue
Item: Forms![Date Selector]![Call Date]
Expression: Forms![Date Selector]![Call Date]+1
GoToControl
Control Name: [Call Date]
GoToControl
Control Name: [Advance]
SetValue
Item: Forms![Date Selector]![Call Date]
Expression: Forms![Date Selector]![Call Date]-1
GoToControl
Control Name: [Call Date]
GoToControl
Control Name: [Decrease]
- Open the Date Selector form. The date will default to the computer's
date. Click the > button to increase the date. Click the < button to
decrease the date.
The date will continue to change while the button is depressed. Note
that although the pointer can be moved into the Date text box with the
TAB key, the date cannot be changed except by using the command buttons.
REFERENCES
For more information about the Screen.ActiveControl property, search the
Help Index for "ActiveControl," or ask the Microsoft Access 97 Office
Assistant.