Results 1 to 7 of 7
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    searching 2nd column in multi-column listbox?

    Can anybody provide a basic way to search through a multi column listbox?

    Basically, I'm adding two columns of data to a listbox at the click of a button. The 2nd column is names. Before being added to the listbox, I want to check that the name has not already been added already. If it has been added already, I am exiting the sub and trying again. What's the best way to compare a string value to the 2nd column of a list box? I've been trying for about a week and I'll I've been able to do is crash my program.



    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, you could certainly loop the items in the listbox, but I'd probably test the underlying table with a DCount().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    Is this the correct way to do it?

    For i = 1 To Me.lstTest.ListCount - 1
    If empName = Me.lstTest.Column(1, i) Then

    PS: i starts at "1" because I have column headers and they don't need to be searched

  4. #4
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    Also, there is no underlying table. it's unbound listbox. basically, i'm running a random function, and i want to make sure that the same employee isn't being randomly selected twice when the button is clicked.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Looks about right; does it work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    no, it made my program unresponsive lol.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the rest of the code? You might have an endless loop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Update Column from Multi-select listbox
    By jhargram in forum Forms
    Replies: 4
    Last Post: 02-27-2012, 12:03 PM
  2. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  3. Searching column history
    By feenixfire in forum Access
    Replies: 8
    Last Post: 08-05-2011, 10:27 AM
  4. Using Multi-column look-up tables
    By Reh in forum Database Design
    Replies: 4
    Last Post: 07-30-2011, 01:50 PM
  5. Use of Lookup Column Versus Listbox
    By P5C768 in forum Access
    Replies: 2
    Last Post: 02-25-2010, 02:00 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