ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   combobox value blank (https://www.excelbanter.com/excel-programming/407805-combobox-value-blank.html)

ranswert

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

Dave Peterson

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

ranswert

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


JLGWhiz

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


ranswert

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


Dave Peterson

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

JLGWhiz

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


ranswert

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


ranswert

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


Dave Peterson

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


All times are GMT +1. The time now is 05:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com