Results 1 to 3 of 3

Thread: 2 list boxes and sql and access **RESOLVED**

  1. #1
    Member
    Join Date
    Sep 02
    Posts
    45

    2 list boxes and sql and access **RESOLVED**

    EDIT: Answer found, just use this code.

    Code:
    Dim strSQL As String
    Dim selectedLstChildCompanies As String
    selectedLstChildCompanies = CStr(LstParentCompanies)
    strSQL = "select Name from CUSTOMER_INFO where Parent_Company = " + selectedLstChildCompanies
    lstChildCompanies.RowSource = strSQL







    Greets,

    It s been awhile since I programmed, so I am pulling a blank here.

    2 tables. We ll call them table PARENT_COMPANY and table CUSTOMER_INFO.

    PARENT_COMPANY has ID (autonum) and Parent_Company_Name .

    CUSTOMER_INFO has Name and Parent_Company(number). Parent_Company is a foreign key of the table PARENT_COMPANY.

    Ok, now.

    2 list boxes, each with a table.

    The user clicks the first, selects a Parent_Company_Name. I can do that.

    Next the 2nd list box is populated with all of the possible Names from Customer_Info (Parent_company has multiples customers). Obviously, they are linked between PARENT_COMPANY.ID and CUSTOMER_INFO.Parent_Company.

    I am doing this from within a form within access 97. So all the info I found online involved openning, connecting etc to a DB which muttled me up since I am already in the DB. I remeber there was a way to do something like this utilizing subforms and child paret type things.

    But at this point I would do it in pure VBA.

    Thoughts?
    Last edited by IwishIcouldprog; Jun 4th, 2004 at 08:50 AM.

  2. #2
    Fanatic Member ahara's Avatar
    Join Date
    Nov 03
    Location
    Toronto
    Posts
    531
    so you want to do this in VB or VBA? I don't really know VBA for Access, but in VB this would be quite simple:

    Populate ListBox with Company Name and use ItemData collection that comes with this control to store the ID

    Capture click event of this list box and form an SQL statement using the ID

    Send the sql statement to a procedure that creates a record set and populates the second list box.

    If you want some code, post back and I will provide (for VB that is

    )

    cheers
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  3. #3
    Member
    Join Date
    Sep 02
    Posts
    45
    Code would be cool.

Posting Permissions

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