ACC: Form Controls to Increment and Decrement a Date

Last reviewed: April 2, 1997
Article ID: Q103194
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:

  1. Create a new form not based on any table or query and name it Date Selector.

  2. 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.

  3. 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.
    
    

  4. 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]
    
    

  5. 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.


Additional query words: date/time
Keywords : FmsEvnt kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.