Results 1 to 9 of 9
  1. #1
    Jack_sparrow007 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Posts
    4

    Add data to listbox by VBA

    Hi All,



    This is my first post,

    I have two list box LISTBOX1 AND LISTBOX2 and a table which contains two columns COLUMN A & COLUMN B.

    LISTBOX1 contains unique data of COLUMN A.

    When I click particular data in LISTBOX1, Needs to apply filter in COLUMN A based on selected data. and pick the unique data of COLUMN B needs to insert into LISTBOX2.

    I am new to Access, don't know how to " apply filter and get unique values and insert into LISTBOX2"

    Thanks in Advance

  2. #2
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Sounds like you want what is called "Cascading Combo Boxes", or in your case, List boxes.

    The attached has an example using cascading combo boxes, but you should be able to just change the object to a list box.
    Attached Files Attached Files

  3. #3
    Jack_sparrow007 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Posts
    4
    Its not working,

    Instead of apply filter, does it possible to run queries when i click data in list box 1.

  4. #4
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Yes. You would just change the AfterUpdate code to
    Code:
     docmd.openQuery "YourQueryNameHere"

  5. #5
    Jack_sparrow007 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Posts
    4
    Yes. you are right, But the criteria for query may vary each time, we select any data in listbox1 during run time.
    ex :
    Code:
    'SELECT DISTINCT COL2
    FROM [Table1]; where COL1 =' LIST1.VALUE

  6. #6
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Then you would set the boundary in your query based on the value in List1, not in the VBA. Use this reference in your query of COL1 of Table1 (based on your response) -
    [Forms]![YourFormNameHere]!
    [List1]

  7. #7
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Forms!YourFormNameHere!List1

    Don't know why it looks funny in the first response. Use brackets around each group.

  8. #8
    Jack_sparrow007 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Posts
    4
    when I execute a query , it has shown in seperate window, not added in Listbox.

    Any Idea to insert such data into listbox.

  9. #9
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    If the query is the data source to your list boxes, it should not show in a separate window.

    Can you make a copy of your database, remove confidential information, and share it for further analysis?

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

Similar Threads

  1. add data from listbox to textboxes
    By sireesha in forum Access
    Replies: 3
    Last Post: 10-16-2012, 11:45 AM
  2. import all data from listbox to a textbox
    By mikael in forum Access
    Replies: 8
    Last Post: 09-09-2012, 07:16 PM
  3. How do I get data from a listbox?
    By cowboy in forum Programming
    Replies: 1
    Last Post: 06-15-2010, 02:28 PM
  4. Replies: 1
    Last Post: 04-09-2009, 09: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