KeyPress: how to delete last character

P

Paul Martin

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
 

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

Similar Threads


Top