Solved

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

Posted on 2006-11-20
4
366 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 63 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 62 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

733 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