Solved

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

Posted on 2006-11-20
4
338 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
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

914 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

16 Experts available now in Live!

Get 1:1 Help Now