+ Reply to Thread
Results 1 to 4 of 4

erratic listbox behavior

  1. #1
    Mark Olsen
    Guest

    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. #2
    sebastienm
    Guest

    RE: 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. #3
    Tom Ogilvy
    Guest

    Re: 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" <MarkOlsen@discussions.microsoft.com> wrote in message
    news:C83E0785-E4A5-4736-A20E-157F3517B314@microsoft.com...
    > 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. #4
    Mark Olsen
    Guest

    Re: 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" <MarkOlsen@discussions.microsoft.com> wrote in message
    > news:C83E0785-E4A5-4736-A20E-157F3517B314@microsoft.com...
    > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1