Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

791 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