When Key Press =,+, is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day
This code is a input feature that shows how to take a keypress on a textbox and either add, subtract or set current date. + key will add 1 day, - will subtract ond day, and = sets current date. This helps with getting dates from users.
Assumes
Just open a new project, add a text box and paste code. Enjoy
Rate When Key Press =,+, is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day
(4(4 Vote))
Private Sub Form_Load()
Text1 = Date
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is = 61
KeyAscii = 0
Text1 = Date
Case Is = 43
KeyAscii = 0
If Text1 = "" Then
Text1 = DateAdd("d", 1, Date)
Else
Text1 = DateAdd("d", 1, Text1)
End If
Case Is = 45
KeyAscii = 0
If Text1 = "" Then
Text1 = DateAdd("d", -1, Date)
Else
Text1 = DateAdd("d", -1, Text1)
End If
End Select
End Sub
When Key Press =,+, is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day Comments
No comments yet — be the first to post one!
Post a Comment