Rolling dates by pressing "+" or "-"

        4 votes: *****      2,746 views      0 comments
by Allen Browne, 20 April 2005    (Access 2+)

Microsoft Access Tips for Serious Users

Provided by Allen Browne,

Rolling dates by pressing "+" or "-"

Some commercial programs (Tracker, Quicken, etc) allow the user to press "+" or "-" to increment or decrement a date without the hassle of selecting the day part of the field and entering a new value. This is especially useful in fields where the default date offered could be a day or two different from the date desired.

To provide this functionality in Access, attach this Event Procedure to the KeyPress event of your control.

Select Case KeyAscii
    Case 43            ' Plus key
        KeyAscii = 0
        Screen.ActiveControl = Screen.ActiveControl + 1
    Case 45            ' Minus key
        KeyAscii = 0
        Screen.ActiveControl = Screen.ActiveControl - 1
    End Select

When any alphanumeric key is pressed, Access passes its ASCII value to your event procedure in the variable KeyAscii. The code examines this value, and acts only if the value is 43 (plus) or 45 (minus). It destroys the keystroke (so it is not displayed) by setting the value of KeyAscii to zero. The active control is then incremented or decremented.

This idea is not limited to dates, or even textboxes. The code can be adapted for other keystrokes as required. Use the KeyDown event to distinguish between the two plus keys (top row and numeric keypad), or to trap control keys such as {Esc}. Anyone feel like reprogramming an entire keyboard?

Home Index of tips Top

Rate this article:   Your rating: Poor Your rating: Not so good Your rating: Average Your rating: Good Your rating: Excellent

This is a cached tutorial, reproduced with permission.

Have your say - comment on this article.

What did you think of 'Rolling dates by pressing "+" or "-"'?

No comments yet.

Why not be the first to comment on this article?!

Have your say...

E-mail (e-mail address will be kept private)
Verify Code
Verification Code

It may take 30 seconds after clicking submit - please be patient to avoid duplicate submissions.  

All comments must be approved before being displayed on this web page.  This process may take up to 24 hours.