erratic listbox behavior

G

Guest

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 >, <,

'------------------------------------------------------------------------------------------
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
 
G

Guest

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 :)
 
T

Tom Ogilvy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top