Advance date field?

  • Thread starter Thread starter Jim
  • Start date Start date
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
 
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)
 
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.
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top