Results 1 to 3 of 3

Thread: Textbox allow delete only

  1. #1
    Guest

    Question

    I'm quite new to VB so please excuse this question.

    I have a textbox on a form. Users may access the textbox and delete what's in it (by hitting backspace / delete) but may not edit the field otherwise.

    Right now I check the key in the keypress event. If it isn't backspace or delete I change the keyascii to vbkeyescape. This works but I'm sure there is a better way to do this.

    Any suggestions?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't set it to vbKeyEscape, just set KeyAscii to 0 to disable the event. Otherwise a spurious Escape keycode will appear.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii <> vbKeyBack Then KeyAscii = 0
    End Sub
    Chemically Formulated As:
    Dr. Nitro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width