Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2005
    Posts
    32

    Unanswered: ListIndex property bug

    I just discovered a bug with the ListIndex property that I've verified with Access 2000 and Access 2003. Briefly, here's the bug:

    If there is an entry is the combo box that contains a hypen "-" the very next entry in the combo box will return a -1 in the listindex property.

    For example, given the following combo box data:

    1234 cbo.ListIndex = 1 actual cbo.ListIndex value returned is 1
    2345 cbo.ListIndex = 2 actual cbo.ListIndex value returned is 2
    12-3 cbo.ListIndex = 3 actual cbo.ListIndex value returned is 3
    3456 cbo.ListIndex = 4 actual cbo.ListIndex value returned is -1
    7891 cbo.ListIndex = 5 actual cbo.ListIndex value returned is 5

    I have an application that populates a combo box via a select query. I chose not to set the LimitToList property to YES. I wanted to catch that via code and display a message rather than having the default Access message displayed. My code was:

    if cbo.listindex < 0 then ... display message and exit

    My combo box has 15,000 entries in it with only 131 containing a hyphen which is why the code worked 99% of the time.

    Hope this information is helpful to you.

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    Try using the absolute value;

    if abs(cbo.listindex) < 0
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Mar 2005
    Posts
    32
    OK, that worked ... sort of. The value returned was 1 (for the 4706th item in the list which was the one after the one with the "-").

    When focus returns to the combo box, you are at the beginning of the list (because the listindex value = 1 (or -1)) rather than being at the 4706th item.

    If you selected the item right before the one with the "-" (i.e. the 4704th item), the abs(cbo.lindex) = 4704. When focus returns to the combo box you are at the 4704th item.

    So, this does not really return the actual listindex value but it does get around the code check to see if the value was at least in the cbo.

    Thanks!

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by garethdart
    Try using the absolute value;

    if abs(cbo.listindex) < 0
    I'm confused: that will always return true...
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Agree... the ABS solution is flawed, it is meant to return a 4 not TRUE.

    I've never noticed this bug as I never use ListIndex
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I meant False
    George
    Home | Blog

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    ^^ That too!
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Quote Originally Posted by tater
    I just discovered a bug with the ListIndex property that I've verified with Access 2000 and Access 2003. Briefly, here's the bug:

    If there is an entry is the combo box that contains a hypen "-" the very next entry in the combo box will return a -1 in the listindex property.

    For example, given the following combo box data:

    1234 cbo.ListIndex = 1 actual cbo.ListIndex value returned is 1
    2345 cbo.ListIndex = 2 actual cbo.ListIndex value returned is 2
    12-3 cbo.ListIndex = 3 actual cbo.ListIndex value returned is 3
    3456 cbo.ListIndex = 4 actual cbo.ListIndex value returned is -1
    7891 cbo.ListIndex = 5 actual cbo.ListIndex value returned is 5

    I have an application that populates a combo box via a select query. I chose not to set the LimitToList property to YES. I wanted to catch that via code and display a message rather than having the default Access message displayed. My code was:

    if cbo.listindex < 0 then ... display message and exit

    My combo box has 15,000 entries in it with only 131 containing a hyphen which is why the code worked 99% of the time.

    Hope this information is helpful to you.
    I'm confused.

    I just made a combobox and based it on a table which had values such as: a, a-one, a - one, b, b-one, b - one, etc...

    I made it so a msgbox displays the .listindex value after selecting a value in the combobox and every .ListIndex (regardless of which I select) returns what it is supposed to (ie...1, 2, 3, 4, etc...)

    RecID CodeV ActualValue
    1 a A-One
    2 b B Good
    3 c C Good
    4 d D Good
    5 e-one E One
    6 -a ax
    7 v -ax
    8 y -d
    9 z dd
    10 1234 xxxx
    11 1245 vvvv
    12 12-3 xxx
    13 1345 vvvv

    Above is the actual values I use for the combobox and they all return a good .ListIndex value (no negatives) if I do a msgbox me.cboCombobox.listindex in the AfterUpdate event.

    Are you sure something else isn't going on with the way you're populating the listbox with values (the thing different I didn't do is populate the values for the combobox via code - I just based it on a query containing the above values.)

    I tried this on both 2000 and 2003.
    Last edited by pkstormy; 10-02-08 at 04:13.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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