Changing the Vaule of a Date field in continuous form

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Is there a way to change the value of a date field in a
continous form forward or back a single day without the
user having to overtype the field? For example, the date
field defaults to the current date, the user enters the
field and presses '+' to change the value to the following
day. Thanks
 
You would need some vba to do this, but it should be doable. Use the keypress
event of the relevant control. Here is some sample UNTESTED code with no error
handling to get you started.


Private Sub txtDateField_KeyPress(KeyAscii As Integer)

If KeyAscii = Asc("+") Or KeyAscii = Asc("-") Then
With Me.txtDateField
If IsDate(.Text) Then
If KeyAscii = Asc("+") Then
.Text = DateAdd("d", 1, .Text)
ElseIf KeyAscii = Asc("-") Then
.Text = DateAdd("d", -1, .Text)
End If
End If
End With

KeyAscii = 0 'ignore plus or minus, allow all other input
End If

End Sub
 
Back
Top