Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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






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
Automatic Completion Erratic jimjomac Excel Discussion (Misc queries) 1 February 3rd 08 05:10 PM
SUM formulas exhibiting erratic behavior Mango Excel Discussion (Misc queries) 3 May 9th 07 03:19 PM
Erratic Cursor Behavior Cathy C Excel Discussion (Misc queries) 6 June 18th 05 04:17 PM
Erratic Behaviour of Buttons Roger PB Excel Programming 3 April 5th 05 05:59 PM
Strange (forms) ListBox behavior steve Excel Programming 0 July 23rd 03 05:46 PM


All times are GMT +1. The time now is 06:37 AM.

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

About Us

"It's about Microsoft Excel"