Solved

Increment a date field with a key press (up or down arrow, for instance)?

Posted on 2006-11-20
4
327 Views
Last Modified: 2008-02-01
I have a data entry form with a date field.  Every five to ten entries requires the user to enter a new date - usually one or two days from the current default date.  The default date is updated each time a new date is entered.

Anyway, I'd like to provide the user with the ability to increment the date one day up or one day down with the up arrow or the down arrow, respectively.

Would the code be set up to detect if the key pressed was the up or down arrow key and then carry out the appropriate increment?

Thanks in advance,

BH
0
Comment
Question by:buckyhenson
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 63 total points
Comment Utility
AFAIK the up and down arrow keys don't have associated ascii values that can be used like that in a keypress event.  Would you settle for two small command buttons, with the up and down arrow images on them (each about half the height of your textbox), stacked vertically and placed immediately next to your textbox?  The code in the buttonclick events would be:

Private Sub cmdUp_Click()
    Me.txtDate = DateAdd("d", 1, me.txtDate)
end sub

Private Sub cmdDown_Click()
    Me.txtDate = DateAdd("d", -1, me.txtDate)
end sub
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 62 total points
Comment Utility

try this, this assuming that TextDate is a bound control to a date field

Private Sub TextDate_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
    Case vbKeyPageUp    ' add date
        KeyCode = 0
        Screen.ActiveControl = Screen.ActiveControl + 1
    Case vbKeyPageDown  ' subtract date
        KeyCode = 0
        Screen.ActiveControl = Screen.ActiveControl - 1
       
End Select

End Sub
0
 

Author Comment

by:buckyhenson
Comment Utility
As of today, my users don't want a tab stop on the date field.  They want to skip over it, having to click on it only when they have to change the date.

So, the command button idea may work best.

Assuming, however, that we will eventually return to having a tab stop on the field, the "Case vbKeyPageUp" idea will work best.

Killer answers from both.

Thanks,

BH
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
>Killer answers from both.
Thank you very much for the compliment.  Glad to help.

I love indecision on the part of the end-user!  If we didn't have indecisive users, we'd all be out of jobs.  ;-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now