Re: Command Button question
- From: "Tom Ogilvy" <twogilvy@xxxxxxx>
- Date: Sun, 5 Nov 2006 14:59:15 -0500
Sub listbox1_change()
If Trim(ListBox1.Value) = "" or Listbox1.ListIndex = -1 Then
Edit_Name.Enabled = False
Delete_Name.Enabled = False
Else
Edit_Name.Enabled = True
Delete_Name.Enabled = True
End If
End Sub
--
Tom Ogilvy
"Patrick Simonds" <ordnance1@xxxxxxxxxxx> wrote in message
news:utknnOQAHHA.3380@xxxxxxxxxxxxxxxxxxxxxxx
Thanks guy here is the code I ended up with, and it works fine, but, there
always seems to be a but.
The source for ListBox1 is a work*** which has a list of all employees
by job category separated by a blank row between each category, so of
course this blank space appears in the ListBox (which is good because it
provides a visual separator between job categories. So in addition to what
the code below achieves I also need the Edit_Name and Delete_Name buttons
disabled when the blank space between job categories is selected.
Sub listbox1_change()
If ListBox1.ListIndex = -1 Then
Edit_Name.Enabled = False
Delete_Name.Enabled = False
Else
Edit_Name.Enabled = True
Delete_Name.Enabled = True
End If
End Sub
"Kai Uwe Schmidt" <nc-schmidka@xxxxxxxxxxxxx> wrote in message
news:eik8t0$cql$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Patrick,
when no selection is made, ListBox.ListIndex has the value -1 (otherwise,
it has a value from 0 to Listbox.Listcount -1).
Public Sub ChangeRowSource ()
If listbox1.listindex = -1 then
MsgBox "Please Select a name first!" : Exit Sub 'quick and very
dirty.
Else
..
End if
End Sub
Regards,
Kai
"Patrick Simonds" <ordnance1@xxxxxxxxxxx> schrieb im Newsbeitrag
news:OtWwUnKAHHA.4992@xxxxxxxxxxxxxxxxxxxxxxx
On my UserForm I have a ListBox (ListBox1) and 2 Command Buttons (Edit
Name, Delete Name). When I click on one of the two command buttons it
runs code to go to the source for the ListBox and selects the name and
then allows you to Edit or Delete the name.
What I need is a piece of code which will prevent the code associated to
either Command Button from running if no name is selected in ListBox1
I tried:
EditName ()
If ListBox1.Value = "" Then GoTo BlankList
My Code here
BlankList:
End Sub
.
- Follow-Ups:
- Re: Command Button question
- From: Patrick Simonds
- Re: Command Button question
- References:
- Command Button question
- From: Patrick Simonds
- Re: Command Button question
- From: Kai Uwe Schmidt
- Re: Command Button question
- From: Patrick Simonds
- Command Button question
- Prev by Date: Re: Transferring (Copy/Paste) Info to another excel workbook
- Next by Date: Re: Chart to PPT
- Previous by thread: Re: Command Button question
- Next by thread: Re: Command Button question
- Index(es):
Loading