View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych Tim Zych is offline
external usenet poster
 
Posts: 389
Default KeyPress: how to delete last character

Add KeyAscii = 0 after the date adjustments.
--
Tim Zych
SF, CA

"Paul Martin" wrote in message
oups.com...
I have a Userform that captures a date in a TextBox. I wish to allow
some user shortcuts whereby the user presses a keyboard character to
modify the date. For example, "+" increases the date by 1 day and "-"
reduces it by one day.

I have this working, but the keyed value is added to the TextBox.

For example, if the date is "1/1/07", pressing "+" will add a day like
this "2/1/07+".

I wish to remove the "+".

I tried deleting the last character in the KeyUp event, but this
removes the 7 but keeps the "+".

My code is:

Private Sub txtDate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With txtDate
Select Case KeyAscii
Case ASC_PLUS: .Value = DateValue(.Value) + 1
Case ASC_MINUS: .Value = .Value - 1
Case Else: Exit Sub
End Select

.Text = Format(.Text, "d/mm/yy")
End With
End Sub

Thanks in advance

Paul Martin
Melbourne, Australia