PDA

View Full Version : Solved: Userform textbox and combination box problem



hunsnowboard
10-14-2009, 01:23 AM
Hi there Everyone!

I have the following problem:
I have a userform in a document. In the userform there is one textbox and a combination list box. The choice in the combination list is free however, there is a help from the textbox. I made an if statement. If the first value of textbox is equal or bigger than 8 then the value of combination list should be “azonosito” and if the first value of the textbox less than 8 then the value of the combination list should be “szam”. If the value of the textbox is Null (which means empty, right?) than the value of the combination list should be also empty. Here is the code:



If Left(TextBox1, 1).Value >=8 Then
Comb_Box1.value = “azonosito”
Elseif Left(TextBox1, 1).Value <8 Then
Comb_Box1.value = “szam”
Elseif TextBox1.Value = Null Then
Comb_Box1.Value = “”
End If


Before I write anything in the textbox1 the value of the combination box is empty. If I write any number in the textbox1, the combination box value is working good. And here is my problem, if I delete everything in the textbox1, the value of the combination box remains “azonosito”, however it should be empty. Why is my code not working properly? What is the problem? :dunno

Thank you in advance for your help!

Tinbendr
10-14-2009, 05:31 AM
You'll have to use the Textbox1 Change or Exit event to reset the combobox.

hunsnowboard
10-14-2009, 05:43 AM
I use textbox1_change event!

fumei
10-14-2009, 10:16 AM
"And here is my problem, if I delete everything in the textbox1, the value of the combination box remains “azonosito”, however it should be empty. Why is my code not working properly? What is the problem? "

The problem is "if I delete everything in the textbox1". That does NOT make it Null.

hunsnowboard
10-14-2009, 12:07 PM
Hi fumei! Thank You for the remark, but it would be more helpful for me if You also explained and showed the solution.

fumei
10-14-2009, 01:19 PM
I thought it was clear. It is NOT Null.

If Left(TextBox1, 1).Value >=8 Then
Comb_Box1.value = “azonosito”
Elseif Left(TextBox1, 1).Value <8 Then
Comb_Box1.value = “szam”
Elseif TextBox1.Value = "" Then ' NOT Null!
Comb_Box1.Value = “”
End If

hunsnowboard
10-14-2009, 01:51 PM
Hi fumei! Thank You for the help! I tried also this solution, but same...:( It is not working! Did you try it on Your userform? Did it work?

geekgirlau
10-14-2009, 09:50 PM
The issue is that a text box contains text.

You need to test for an empty string first, because an empty string is also less than "8". Also note that I'm testing for the text "8" not the number 8.


Private Sub TextBox1_Change()
Select Case Left(Me.TextBox1.Value, 1)
Case "": Comb_Box1.Value = ""
Case Is >= "8": Comb_Box1.Value = "azonosito"
Case Is < "8": Comb_Box1.Value = "szam"
End Select
End Sub

hunsnowboard
10-15-2009, 08:44 AM
Hi Geekgirlau!

Thank You so much for the solution! It is working and besides You also taught me a new way to use the Select Case function!
Thank You again!