+ Reply to Thread
Results 1 to 2 of 2

Pressing any key in any textbox clears a cell?

Hybrid View

scadaman29325 Pressing any key in any... 01-23-2008, 08:03 AM
mikerickson Each control has its own... 01-23-2008, 09:46 AM
  1. #1
    Registered User
    Join Date
    11-28-2007
    Posts
    57

    Pressing any key in any textbox clears a cell?

    I thought I saw this title a few weeks ago, but can't find it.

    With data retrieved from a search into the form, if any key is pressed (in any textbox), I want it to clear the one textbox (or controlsource).

    I tried the below, but it does not run when I press a key.

    
    Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    
        txtNewWOnum.Text = ""
    
    End Sub
    Thanks again for your help, Phil.
    Phil
    Technician
    City of Clinton, SC
    SCADA, GIS, Utility Billing, Networking
    I'm doing the best I can with the little bit I know.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Each control has its own KeyPress event. This will clear TextBox1, but I don't see how the user can enter anything into TextBox1.

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
        Me.TextBox1.Text = vbNullString
    End Sub
    Perhaps this will do what you want and also allow the user to enter something in TextBox1.
    Private Sub TextBox1_Enter()
    With Me.TextBox1
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
    End Sub
    Last edited by mikerickson; 01-23-2008 at 09:53 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1