Golfer219
asked on
ComboBox Value Empty
I'm trying to write code that hides certain objects on a user form if a combobox's value is empty. I've tried a series of different options but can't seem to get it. I was thinking something along the lines of
If UserForm1.ComboBox1.Value = Null Then
or
If UserForm1.ComboBox1.Value = "" Then
or
If UserForm1.ComboBox1.Value = Empty Then
Thanks for the help!
If UserForm1.ComboBox1.Value = Null Then
or
If UserForm1.ComboBox1.Value = "" Then
or
If UserForm1.ComboBox1.Value = Empty Then
Thanks for the help!
Try:
If Trim(UserForm1.ComboBox1.V alue) = vbNullString Or UserForm1.ComboBox1.ListIn dex = -1 Then
Kevin
If Trim(UserForm1.ComboBox1.V
Kevin
ASKER
Thanks for the help. I mocked up a quick test file to show you what I'm trying to do. When you click the control to show the user form, both list boxes and the command button should be hidden since nothing is selected in the combobox.
Thanks!
ComboBox-Test.xls
Thanks!
ComboBox-Test.xls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this in your Userform1 code:
And try this in your module:
I tested it and its working here. The load initializes the value to "" and LB/CB's invisible
Then, upon a change they become visible....
Is this where you're headed?
See attached - works for me...
Dave
And try this in your module:
Sub ShowUF1()
Load UserForm1
UserForm1.Show
End Sub
I tested it and its working here. The load initializes the value to "" and LB/CB's invisible
Then, upon a change they become visible....
Is this where you're headed?
See attached - works for me...
Dave
Private Sub ComboBox1_Change()
If ComboBox1.Value <> "" Then
UserForm1.ListBox1.Visible = True
UserForm1.ListBox2.Visible = True
UserForm1.CommandButton1.Visible = True
Else
UserForm1.ListBox1.Visible = True
UserForm1.ListBox2.Visible = True
UserForm.CommandButton1.Visible = True
End If
End Sub
Private Sub ListBox2_Click()
End Sub
Private Sub UserForm_Initialize()
ComboBox1.Value = ""
UserForm1.ListBox1.Visible = False
UserForm1.ListBox2.Visible = False
UserForm1.CommandButton1.Visible = True
End Sub
Private Sub UserForm_Terminate()
Unload UserForm1
End Sub
ComboBox-Test-r1.xls
Whooops - userform code at bottom....
I didn't see Zorvek's last post before i hit send... lol
Dave
I didn't see Zorvek's last post before i hit send... lol
Dave
Good anyway - get a diversity of response... Different strokes - I like to go through the:
Load (which initiates the Initialize() event)
Show
and Unload (via Terminate) approach...
PS - my post sets you up for making them dissappear if the combobox is cleared on the active userform...
ALSO - my post was a bit of an error comedy - for completeness please review code again and file attached:
Cheers,
Dave
Load (which initiates the Initialize() event)
Show
and Unload (via Terminate) approach...
PS - my post sets you up for making them dissappear if the combobox is cleared on the active userform...
ALSO - my post was a bit of an error comedy - for completeness please review code again and file attached:
Cheers,
Dave
MODULE:
Sub ShowUF1()
Load UserForm1
UserForm1.Show
End Sub
USERFORM:
Private Sub ComboBox1_Change()
If ComboBox1.Value <> "" Then
UserForm1.ListBox1.Visible = True
UserForm1.ListBox2.Visible = True
UserForm1.CommandButton1.Visible = True
Else
UserForm1.ListBox1.Visible = False
UserForm1.ListBox2.Visible = False
UserForm1.CommandButton1.Visible = False
End If
End Sub
Private Sub UserForm_Initialize()
ComboBox1.Value = ""
UserForm1.ListBox1.Visible = False
UserForm1.ListBox2.Visible = False
UserForm1.CommandButton1.Visible = False
End Sub
Private Sub UserForm_Terminate()
Unload UserForm1
End Sub
ComboBox-Test-r1.xls
ASKER
Perfect! Thanks a ton!
="" should have worked, but it may not depending on context.
Can you show more code? Like which event are you checking?