View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mark Olsen Mark Olsen is offline
external usenet poster
 
Posts: 8
Default erratic listbox behavior

Ok, I posted something similar to this earlier but Im still having problems.
I have two listboxes where the first one contains a bunch of items and the
second one contains items that are selected from the first box using , <,
, << buttons. Here is some code:



'------------------------------------------------------------------------------------------
Private Sub btnAddSingle_Click()
Dim index As Integer

If lbxUnselected.ListIndex < -1 Then
lbxSelected.AddItem (lbxUnselected.Value)
index = lbxUnselected.ListIndex
lbxUnselected.RemoveItem (index)
End If

End Sub
'-----------------------------------------------------------------------------------------

It seems to work fine visually. The item from one listbox goes to the other
listbox. I check the other listbox and the .Count property is right but the
..Value property returns an empty string. Even more curious, this only
happens sometimes. Sometimes it works perfectly. I have added DoEvents to
clear the event buffer and that seems like it works for a while, but all of
the sudden it will break for apparently no reason. I dont know what do fix
but it seems correct and in fact does occasionally work. Here is where im
trying to pull the values out and am getting an empty string: By the way.
Im new at VBA so my code may be pretty horrible

'------------------------------------------------------------------------------------------

lCount = lbxSelected.ListCount
For i = 0 To (lCount - 1)
lbxSelected.ListIndex = i
For j = 0 To (queryCount - 1)
qName = lbxSelected.Value
If (qName = queryList(j, 0)) Then
If (queryList(j, 1) = "scBudExp") Then
Call runQry("qryBudget")
Call runQry("qryExpenses")
Else
Call runQry(queryList(j, 1))
End If
End If
Next
Next