Incrementing date with + or - key (1 Viewer)

E

ernief

Guest
I have put the following code in the OnKeyPress event of a text box txtProgramDate

Private Sub txtProgramDate_KeyPress(KeyAscii As Integer)
If KeyAscii = 43 Or KeyAscii = 45 Then
If KeyAscii = 43 Then
txtProgramDate.Value = txtProgramDate.Value + 1
Else
txtProgramDate.Value = txtProgramDate.Value - 1
End If
End If
Me.Form.Refresh
End Sub

This increments that date fine but the + or - symbol remains in the box until the text box loses focus. I would really like the amended date to be refreshed as soon as the + or - key is pressed.
The line M.Form.Refresh does not seem to make any difference.
Thanks in anticipation
 
P

Paul Eades

Guest
Try using this code;

Private Sub txtProgramDate_KeyPress(KeyAscii As Integer)
Select Case KeyAscii

Case 45 'or the - (minus key)
txtProgramDate.Value = txtProgramDate.Value - 1
Let KeyAscii = 0

Case 43 'or the + (Plus key)
txtProgramDate.Value = txtProgramDate.Value + 1
Let KeyAscii = 0

End Select
End Sub
 

Users who are viewing this thread

Top Bottom