I don't think you can in Access. I think you can in Visual Basic by adding or subtracting 1 from the stored value that is used for the date (this is a floating point number where the integer part represents the number of days from 30/12/1899 and the decimal fraction part represents part of a day, e.g. '.5' = 12 hours). Then you would use the value in a formatted field to show as a normal date.
I don't think you can do this in Access - usually you have to use DateAdd to tell the system what you are adding (days, months, years etc.) and how many to add, e.g. DateAdd("m", 1, now()) would add one month to today's date.
If anyone knows otherwise, I will be happy to be corrected.
To test this create a form with one named textbox named txtDate, then add the following code to the code module behind the form. Ensure that the Form's KeyPreview Event is set to YES, and that the Form's KeyDown Event is set to [Event Procedure]. Then open the form, press the keys( + and - )
Option Compare Database
Option Explicit
Dim intPrevKey As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Me.ActiveControl = txtDate Then
Select Case KeyCode
Case 107 ' Plus Key on KeyPad
KeyCode = 0
txtDate = DateAdd("d", 1, txtDate)
Case 109 ' Minus Key on KeyPad
KeyCode = 0
txtDate = DateAdd("d", -1, txtDate)
Case 189 ' Minus & Underline Key
If intPrevKey <> 16 And Shift = 0 Then 'Shift Key
KeyCode = 0
txtDate = DateAdd("d", -1, txtDate)
End If
Case 187 ' Equal & Plus Key
If intPrevKey = 16 Or Shift = 1 Then 'Shift Key
KeyCode = 0
txtDate = DateAdd("d", 1, txtDate)
End If
Case Else
'do nothing
End Select
intPrevKey = KeyCode
End If
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.