Microsoft KB Archive/103194

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


ACC: Form Controls to Increment and Decrement a Date

Article ID: 103194

Article Last Modified on 1/18/2007



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition



This article was previously published under Q103194

Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

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: kbhowto kbusage KB103194