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 |
erratic listbox behavior
Are you using multiselect or single select lists? In the first case, it may
return a blank. I would try to change listbox.Value by listbox.List(listbox.listindex) I personnaly never use Value on a listbox... i couldn't tell you the reason though 'cause it's been years i use the List instead :-) -- Regards, Sébastien <http://www.ondemandanalysis.com "Mark Olsen" wrote: 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 |
erratic listbox behavior
Selecting each item in the list to get the value would be the wrong way to
go, particularly if you have any events associated with the listbox. lCount = lbxSelected.ListCount For i = 0 To (lCount - 1) qName = lbxSelected.List(i) For j = 0 To (queryCount - 1) 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 -- Regards, Tom Ogilvy "Mark Olsen" wrote in message ... 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 |
erratic listbox behavior
Thanks guys. Youre solutions worked like a charm.
Mark "Tom Ogilvy" wrote: Selecting each item in the list to get the value would be the wrong way to go, particularly if you have any events associated with the listbox. lCount = lbxSelected.ListCount For i = 0 To (lCount - 1) qName = lbxSelected.List(i) For j = 0 To (queryCount - 1) 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 -- Regards, Tom Ogilvy "Mark Olsen" wrote in message ... 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 |
All times are GMT +1. The time now is 01:26 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com