PC Review


Reply
Thread Tools Rate Thread

combobox value blank

 
 
ranswert
Guest
Posts: n/a
 
      17th Mar 2008
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
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Mar 2008
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
 
Reply With Quote
 
ranswert
Guest
Posts: n/a
 
      17th Mar 2008
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
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      17th Mar 2008
> 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
> >

 
Reply With Quote
 
ranswert
Guest
Posts: n/a
 
      17th Mar 2008
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
> > >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Mar 2008
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
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      17th Mar 2008
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
> > > >

 
Reply With Quote
 
ranswert
Guest
Posts: n/a
 
      17th Mar 2008
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
>

 
Reply With Quote
 
ranswert
Guest
Posts: n/a
 
      17th Mar 2008
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
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Mar 2008
..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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
combobox blank deb Microsoft Access 1 29th Jan 2010 08:06 PM
When Combobox is blank, textboxes should be blank RichW Microsoft Access VBA Modules 7 2nd Nov 2009 07:53 PM
Combobox drops down blank row Albert Microsoft Excel Programming 5 18th Jan 2008 04:17 PM
ComboBox Back To Blank =?Utf-8?B?SmFuaQ==?= Microsoft Access Form Coding 2 14th Sep 2006 11:57 AM
adding a blank row to a combobox Sam Microsoft VB .NET 2 3rd May 2005 03:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:51 AM.