Advance date field?

J

Jim

I'm using Access 2003 and want to advance a date field in a text box by
using the + or - keys like a checkbook program does. I can't find any
examples that explain this.
Thanks for any help
Jim
 
A

Al Campagna

Jim
To increment by +1...
DateField = DateField + 1
or
DateWorked = DateAdd("d", +1, DateWorked)

To increment by -1...
DateField = DateField -1
or
DateWorked = DateAdd("d", -1, DateWorked)
 
K

Klatuu

Al has the formula you need. I always use the DateAdd even though adding 1
to a date works, it is a matter of form and habit. When I see Something +1,
I assume Something is a number. If I see DateAdd("d",1,Something) I know
Something is a data I am adding 1 day to.
Enough preaching.

To use the + and - , you can use the keypress event Look up the details in
VBA Help. There should be enough info there to get you started.
 
J

Jeff Boyce

Jim

To add to Al's code, you'll need to intercept the keystrokes to determine if
the "+" or "-" key was pressed, so you could then run Al's code.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
A

Al Campagna

Jim,
After reading Klatuu's and Jeff's reply, I see I misread what you really wanted.

Ex. Field [DateField]...

Set the form's Key Preview to Yes and...

Private Sub DateField_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyAdd Then
DateField = DateAdd("d", 1, DateField)
KeyCode = 0
ElseIf KeyCode = vbKeySubtract Then
DateField = DateAdd("d", -1, DateField)
KeyCode = 0
End If
End Sub
 
J

Jim

Thanks for the information. I will look in the help file for the keypress
event and see if I can get it to work.

Jim
 
Top