Results 1 to 10 of 10
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154

    Retrieving the value in 2nd column of List Box

    This is how I go about in retrieving the value in the first column of a list box that has column count = 2



    Code:
    For i = 0 To Me.Controls("lstBox").ListCount - 1
         debug.print Me.Controls("lstBox").ItemData(i)
    Next i
    I want to retrieve the value in the 2nd column and I tried doing this:
    Code:
    For i = 0 To Me.Controls("lstBox").ListCount - 1
         debug.print Me.Controls("lstBox").ItemData(i,2)
    Next i
    but I get an error saying "Wrong number of arguments or invalid property assignment"

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    columns are indexed from zero so first column is .column(0), second column is .column(1)

  3. #3
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    So how should the final code look like then?

    I tried doing this:

    Code:
    For i = 0 To Me.Controls("lstBox").ListCount - 1
         debug.print Me.Controls("lstBox").ItemData(i, .column(1))
    Next i
    and this:

    Code:
     For i = 0 To Me.Controls("lstBox").ListCount - 1
    debug.print Me.Controls("lstBox").column(1).ItemData(i)
     Next i
    none of them work.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    For i = 0 To lstBox.ListCount - 1

    debug.print lstBox.ItemData(I,1)

    next i

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    or perhaps

    debug.print lstBox.ItemData(I).column(1)

  6. #6
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    tried as per your suggestions and not working, get an error

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    get an error
    how does that statement help me to help you?

  8. #8
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Quote Originally Posted by Ajax View Post
    For i = 0 To lstBox.ListCount - 1

    debug.print lstBox.ItemData(I,1)

    next i

    Run-time error '450'
    Wrong number of arguments or invalid property assignment

  9. #9
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Quote Originally Posted by Ajax View Post
    or perhaps

    debug.print lstBox.ItemData(I).column(1)
    Run-time error 424
    Object required

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Pulling th column value from list box
    By Shamli in forum Access
    Replies: 1
    Last Post: 08-23-2018, 04:27 PM
  2. Replies: 2
    Last Post: 08-14-2017, 06:22 AM
  3. Replies: 1
    Last Post: 03-17-2012, 08:49 PM
  4. Replies: 11
    Last Post: 01-26-2012, 09:28 AM
  5. List box column check..
    By empyrean in forum Programming
    Replies: 1
    Last Post: 10-28-2009, 08:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums