View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default listbox click event help

Yes, your code will be like this:

At the top (in the declarations section) of your form code have this:

private bCancelClick as Boolean

Then your altered code will be:

In the commandbutton:
----------------------------------

bCancelClick = True

'If no selection is made in the listbox then create a new
listbox item...
If ListBox1.ListIndex = -1 Then
ListBox1.AddItem TextBox1.Value
ListBox1.List(ListBox1.ListCount - 1, 1) =
TextBox2.Value
ListBox1.List(ListBox1.ListCount - 1, 2) =
TextBox3.Value
'Else if a selection is made in the listbox, update the
values
'to those in the textboxes.
Else
ListBox1.List(ListBox1.ListIndex, 1) =
TextBox1.Value
ListBox1.List(ListBox1.ListIndex, 2) =
TextBox2.Value
ListBox1.List(ListBox1.ListIndex, 3) =
TextBox3.Value
End If

bCancelClick = False


In the Click event:
------------------------------

Private Sub ListBox1_Click()

If bCancelClick Then
Exit Sub
End If

If ListBox1.ListIndex < -1 Then
TextBox1.Value = ListBox1.List(ListBox1.ListIndex, 1)
TextBox2.Value = ListBox1.List(ListBox1.ListIndex, 2)
TextBox3.Value = ListBox1.List(ListBox1.ListIndex, 3)
End If

End Sub


RBS


"Michael Malinsky" wrote in message
ups.com...
I'm not sure I follow...can you expand on your response?

Thanks,
Mike.