Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Command Button question

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Command Button question

You could use the listbox events to control the commandbuttons enabled
status, rather than let the button be pressed only to do nothing!

something like....

sub listbox1_change
if listbox1.listindex = 0 then
commandbutton1.enabled = true
else
commandbuton1.enabled = false
endif
end sub

Put the commandbuton1.enabled = false in the form initialize event.


--
Cheers
Nigel



"Patrick Simonds" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Command Button question

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" schrieb im Newsbeitrag
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Command Button question

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 worksheet 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" wrote in message
...
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" schrieb im Newsbeitrag
...
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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Command Button question

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" wrote in message
...
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 worksheet 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" wrote in message
...
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" schrieb im Newsbeitrag
...
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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Command Button question

Thanks, but it does not enable the buttons when you select a name in the
listbox.


"Tom Ogilvy" wrote in message
...
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" wrote in message
...
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 worksheet 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" wrote in message
...
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" schrieb im Newsbeitrag
...
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









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Command Button question

In contrast, it works fine for me - exactly as intended.

--
Regards,
Tom Ogilvy


"Patrick Simonds" wrote in message
...
Thanks, but it does not enable the buttons when you select a name in the
listbox.


"Tom Ogilvy" wrote in message
...
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" wrote in message
...
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 worksheet 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" wrote in message
...
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" schrieb im Newsbeitrag
...
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











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
Command Button question Giselle[_2_] Excel Programming 7 January 28th 06 03:20 AM
command button question Gary Keramidas[_2_] Excel Programming 4 June 18th 05 08:24 PM
Command Button Question Todd D. Levy Excel Programming 4 July 7th 04 03:18 PM


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

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

About Us

"It's about Microsoft Excel"