Userform textbox selection clears the other texboxes

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

On my userform i have 5 TextBoxes which i use to search for purposes then the listbox is populated.
Currently i can type in each one leaving text in them but im looking to clear each one when another is selected.
See photo example.

What i would like to be able to do is this if you could advise please.

Lets say i type ABC in the first textbox but i then type XYZ in the last textbox.
When i select the last textbox the code should clear the ABC from the first on.
Basically only allowing the user to show text in any one textbox at a time.

I can write an incorrect long winded code but not sure how to do it correctly in only a few lines.
Each TextBox has a custom name.
TextBoxBlank
TextBoxVehicle
TextBoxItem
TextBoxProgrammer
TextBoxChip
 

Attachments

  • 6933.jpg
    6933.jpg
    63.6 KB · Views: 8

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Well....
One (slightly schoolboy) way of achieving this, would be to have a little procedure for emptying ALL of your boxes...
VBA Code:
Sub empty_txtbxs()
    With Me
        .TextBoxBlank.Value = ""
        .TextBoxVehicle.Value = ""
        .TextBoxItem.Value = ""
        .TextBoxProgrammer.Value = ""
        .TextBoxChip.Value = ""
    End With
End Sub
Then within the "Enter" event of each box, call the procedure:
This would be the procedure for "TextBoxBlank", for example:
VBA Code:
Private Sub TextBoxBlank_Enter()
Call empty_txtbxs
End Sub
...You'll need to write similar lines into each of the other boxes' _enter events.
 
Upvote 0
I have this but it makes no difference.

Can you see my error ?

VBA Code:
Private Sub TextBoxBlank_GotFocus()
    Call Clear_TextBox
End Sub
Sub Clear_TextBox()
    With Me
        .TextBoxBlank.Value = ""
        .TextBoxVehicle.Value = ""
        .TextBoxItem.Value = ""
        .TextBoxProgrammer.Value = ""
        .TextBoxChip.Value = ""
    End With
End Sub
 
Upvote 0
All sorted.

changed to Enter like you advise & works.
Vave a nice day
 
Upvote 0
Ah, good; I was just about to answer, too!
Glad it worked, and thanks for the feedback.(y)
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top