Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-20
4
Medium Priority
?
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 252 total points
ID: 17983826
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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 248 total points
ID: 17984986

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
ID: 17991224
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
ID: 17991250
>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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

604 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