B
Billy B
I have the following procedure that is supposed to take the text value from a
cell, convert it to date and when the user presses the + or - key on the
numeric keypad adds or subtracts one day then updates the cell. The + sign on
the keypad works but the minus does not (it just updates the worksheet cell
with the - sign. Here is what I have so far:
Private Sub txtDate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim dtDateShown As Date
Dim dtNewDate As Date
dtDateShown = CDate(txtDate.Text)
dtDateShown = Format(dtDateShown, "mm/dd")
If KeyAscii = 43 Then '+ key pressed
dtNewDate = dtDateShown + 1
dtNewDate = Format(dtNewDate, "mm/dd")
txtDate.Text = Format(CStr(dtNewDate), "mm/dd")
End If
If KeyAscii = 45 Then 'this was the minus key also tried vbKeySubtract
dtNewDate = dtDateShown - 1
dtNewDate = Format(dtNewDate, "mm/dd")
txtDate.Text = Format(CStr(dtNewDate), "mm/dd")
End If
End Sub
cell, convert it to date and when the user presses the + or - key on the
numeric keypad adds or subtracts one day then updates the cell. The + sign on
the keypad works but the minus does not (it just updates the worksheet cell
with the - sign. Here is what I have so far:
Private Sub txtDate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim dtDateShown As Date
Dim dtNewDate As Date
dtDateShown = CDate(txtDate.Text)
dtDateShown = Format(dtDateShown, "mm/dd")
If KeyAscii = 43 Then '+ key pressed
dtNewDate = dtDateShown + 1
dtNewDate = Format(dtNewDate, "mm/dd")
txtDate.Text = Format(CStr(dtNewDate), "mm/dd")
End If
If KeyAscii = 45 Then 'this was the minus key also tried vbKeySubtract
dtNewDate = dtDateShown - 1
dtNewDate = Format(dtNewDate, "mm/dd")
txtDate.Text = Format(CStr(dtNewDate), "mm/dd")
End If
End Sub