Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
Combobox drops down blank row Albert Excel Programming 5 January 18th 08 04:17 PM
ComboBox list reliant on the entry from a different ComboBox ndm berry[_2_] Excel Programming 4 October 4th 05 04:40 PM
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox Minitman[_4_] Excel Programming 3 October 26th 04 07:58 PM
Remove blank rows from combobox Steph[_3_] Excel Programming 1 June 25th 04 05:37 PM


All times are GMT +1. The time now is 04:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"