Changing the Vaule of a Date field in continuous form

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
 
J

John Spencer (MVP)

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
 

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

Top