View Full Version : textbox events?

04-19-2007, 02:38 AM
I have a textbox which has a default text.there is a combobox infront of the textbox in whixh I have the units of the values I input into the text box. combobox is invisible. I want
1) the default text to be removed
2) the combobox to become visible
when the user enters the text into the textbox.
Under which event of the text box should I write? what to write to remove the text?

Simon Lloyd
04-19-2007, 03:03 AM
You can remove text and hide/unhide the textbox or combobox for that matter like this:

Sheets("Sheet1").TextBox1.Value = ""
Sheets("Sheet1").TextBox1.Visible = False
this is assuming the combobox and textbox are located on a worksheet.


04-19-2007, 03:36 AM
This doesn't make sense. What is the default text in your textbox? Something like 'enter data'? Do you want the combobox to appear when they click inside/move to the textbox or after they enter some data? If they enter data why do they need to make another choice from the combobox?

It might be simpler to have the combobox always visible (with a label containing your default text next to it if necessary) and do away with the textbox altogether.

Simon Lloyd
04-19-2007, 03:57 AM
I found it odd too Glen....but then again i'm sure i have asked many odd questions with many odd set-ups, bt the Textbox does seem superfluous as default text is normally ovcerwritten!


04-19-2007, 04:16 AM
what I want to input in the textbox is work. By default it is zero so I put the textbox text 0. in the combobox there are the units like Kw, etc. I want the combo to become visible and 0 to be deleted when the user wants to enter another amount. Is it clear?

04-19-2007, 04:19 AM
Yeah Simon, I'm sure there is a reason (possibly user damage-limitation or usability) but it's hard to tell what it is when you're not looking over the person's shoulder. Simplicity is usually the best policy.

Simon Lloyd
04-19-2007, 04:28 AM
Maryam, try using my suggestion above for hiding/unhiding combobox/textbox you could have these events in the Textbox1_Click event or Combobox1_Click or even the change event depending on how you want it to react...to save yourself lots of posts here why not post your workbook or sample workbook so we can actually see what you are trying to achieve!


04-19-2007, 04:29 AM
here is an example file. The problem is that when I put 2, 0 will be deleted, but if the number is more than one digit there is a problem.

Bob Phillips
04-19-2007, 04:33 AM
I can't put in more than 1 digit.

Seems an odd design to me, I guess I just don't get it.

04-19-2007, 05:03 AM
yes, how can we put more than one digit, but delete 0 when we like to input another value. now I put textbox1.value="" thats why everytime it deletes the last digit.

Bob Phillips
04-19-2007, 05:07 AM
Sorry, I just don't get what you want to do, and why.

Simon Lloyd
04-19-2007, 05:21 AM
Why enter a value only to have it deleted straight away, however you have the max length of the textbox set to 0, not that it matters because the way you have it set up change the textbox and it gets cleared????


04-19-2007, 05:28 AM
I dont want to delete the value after it is entered!
See We have a text box which has a value(text)in the begining ( which is
zaro)and a combobox which is invisible in the beginning.
we want the textbox to become empty to let the user input the new value and the combo to become visible to let him select the unit of the value.
under which event of the text box should we write these two line? how to write the codes?

04-23-2007, 09:07 PM
any reply?

04-24-2007, 01:09 AM

Add following code to the UserForm's code section and remove all other textbox1 events...

Private Sub TextBox1_Change()
If Len(TextBox1.Text) > 0 And TextBox1.Text <> "0" Then
ComboBox1.Visible = True
End If
End Sub