+ Reply to Thread
Results 1 to 4 of 4

Select & Delete text in TextBox1 also deletes text in TextBox2

  1. #1
    Registered User
    Join Date
    11-04-2006
    Posts
    19

    Select & Delete text in TextBox1 also deletes text in TextBox2

    Hi.

    I have a form with 2 textboxes on it, named TextBox1 and TextBox2.

    When the form runs there is some text, (e.g. the letters "abcd") appearing in both textboxes.

    I want to be able to:
    select all the text in TextBox1,
    delete it,
    and then automatically the text in TextBox2 is deleted as well.

    Please could someone tell me if this is possible.

  2. #2
    Registered User
    Join Date
    07-22-2005
    Location
    canada
    Posts
    73

    if I understand you...

    Hello,

    If I understand you correctly, something like this :

    Private Sub TextBox1_Change()
    If TextBox1.Value = "" Then
    TextBox2.Value = ""
    End If
    End Sub


    hope this helps at all,

    oliver.

  3. #3
    Registered User
    Join Date
    11-04-2006
    Posts
    19
    This doesn't solve the problem on it's own.

    It solves the problem and about 5 other things I was trying to work out as well. Thankyou very much!

    Actually what I really wanted was to have whatever I type in TextBox1 appear automatically in TextBox2.

    What I needed was:

    Private Sub TextBox1_Change()

    TextBox2 = TextBox1

    End Sub

    But I didn't know this so I searched really hard in (Excel 2003) Microsoft Visual Basic help and the Microsoft knowledge base and elsewhere and eventually found this in Microsoft Visual Basic help:

    "KeyPress Event Example

    The following example uses the KeyPress event to copy keystrokes from one TextBox to a second TextBox. The user types into the appropriately marked TextBox.

    To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains: Two TextBox controls named TextBox1 and TextBox2.

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As _
    MSForms.ReturnInteger)
    TextBox2.Text = TextBox2.Text & Chr(KeyAscii)

    'To handle keyboard combinations (using SHIFT,
    'CONTROL, OPTION, COMMAND, and another key),
    'or TAB or ENTER, use the KeyDown or KeyUp event.
    End Sub"

    This code has the major disadvantage in that it can't handle people using delete or backspace. This is why I was asking, at the beginning of the thread, how to get select + delete to appear in TextBox2.

    Using the textbox_change event is much more useful. Now, if I use delete or backspace this change actually appears in TextBox2, which is great. Thankyou very much.

    I just feel that I could write a help section that is 10 times better than the one they have provided. And I know nothing about the subject. Is all programming like this?

  4. #4
    Registered User
    Join Date
    07-22-2005
    Location
    canada
    Posts
    73

    Thumbs up sadly..

    Hello,

    Great that it works!,

    and to your last question ...

    Sadly, yes. Code documentation is about as well written as a pig-latin
    interpreted user manual for the space shuttle.

    Cheers,

    Oliver.

+ 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