Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
I have a combo box on a form. Sometimes when the form is called the combo
box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
You could have a subroutine that checks all the input to see if it's valid
before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
Is there a difference in:
'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
Is there a difference in:
'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
Is a blank value in a combo box before the list rowsource is pulled up
concidered a null string. I thought I could do a 'if combobox.value < "" then'. Will this work? Thanks "JLGWhiz" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
Why not use .listindex?
ranswert wrote: Is a blank value in a combo box before the list rowsource is pulled up concidered a null string. I thought I could do a 'if combobox.value < "" then'. Will this work? Thanks "JLGWhiz" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
If Not ComboBox1.Value < 0 Then
Or If ComboBox1.Value < "" Then Either should work. "ranswert" wrote: Is a blank value in a combo box before the list rowsource is pulled up concidered a null string. I thought I could do a 'if combobox.value < "" then'. Will this work? Thanks "JLGWhiz" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
What is 'listindex'?
"Dave Peterson" wrote: Why not use .listindex? ranswert wrote: Is a blank value in a combo box before the list rowsource is pulled up concidered a null string. I thought I could do a 'if combobox.value < "" then'. Will this work? Thanks "JLGWhiz" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson -- Dave Peterson |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
Thanks
I used your code and it works great. "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
combobox value blank
..listindex is a number that represents which item in your list was selected.
The top item has a listindex of 0. So when nothing is selected, listindex is -1. ranswert wrote: What is 'listindex'? "Dave Peterson" wrote: Why not use .listindex? ranswert wrote: Is a blank value in a combo box before the list rowsource is pulled up concidered a null string. I thought I could do a 'if combobox.value < "" then'. Will this work? Thanks "JLGWhiz" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Yes, "" is a null string. " " is a space. The space has a character value whereas the null string has no value. "ranswert" wrote: Is there a difference in: 'If x < "" then' and 'If x < " " then'? Thanks "Dave Peterson" wrote: You could have a subroutine that checks all the input to see if it's valid before you enable the combobox. I made a small userform with a combobox, textbox and two commandbuttons. I wanted to make sure that there was something in the textbox and something in the combobox before enabling the commandbutton2 button. Option Explicit Private Sub ComboBox1_Change() Call CheckInput End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub TextBox1_Change() Call CheckInput End Sub Private Sub UserForm_Initialize() With Me.ComboBox1 .AddItem "A" .AddItem "B" .AddItem "C" .ListIndex = -1 .Style = fmStyleDropDownList End With Me.CommandButton2.Enabled = False End Sub Private Sub CheckInput() Dim Ok As Boolean Ok = True If Me.ComboBox1.ListIndex < 0 Then Ok = False ElseIf Me.TextBox1.Value = "" Then Ok = False End If Me.CommandButton2.Enabled = Ok End Sub ranswert wrote: I have a combo box on a form. Sometimes when the form is called the combo box is blank. I have a button 'OK' that gets the value from the combo box. I that value is blank my code for the 'OK' button doesn't work. There are no blank cell in the row source for the combo box. Is there a property for the combo box that can be set so that it won't have a blank value before the drop arrow is pressed? Thanks -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
fill combobox depending on selection from another combobox | Excel Discussion (Misc queries) | |||
Combobox drops down blank row | Excel Programming | |||
ComboBox list reliant on the entry from a different ComboBox | Excel Programming | |||
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox | Excel Programming | |||
Remove blank rows from combobox | Excel Programming |