Results 1 to 5 of 5

Thread: Using Listboxes

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have a listbox that is filled with a list of tables from a database. The list changes frequently. I need to be able to take a table that the user selects in the listbox and use it to perform other operations, such as deleting the table. How can I do this, since I can't use a Select Case statement???

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Name of the Table the User Selects will be Held in the Text Property which is the Default Property for a Listbox, eg.

    oRs = oDB.OpenRecordSet("SELECT * FROM " & List1, dbOpenforwardOnly) 'Select All Records From Table Selected in List1

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Ok, that will work for opening the table, but if I just need the name that is selected in the listbox, then how would I go about extracting that from VB? Would that just be in the listbox.text property? Is that what you meant by the first part of your reply? Thanks.

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  4. #4

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    What I need to be able to do is use the listbox to open another form (say the form name is "frmCustomer"), that has the same name as the table that is selected (when the table name is "Customer"). But I can't figure out how to get the name in the listbox into a .show command. Can you enlighten me? I hope you can. Or possibly show me another way I can accomplish the same thing. If I need to rename the form in order to make it work, that's no big deal. Thanks.

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Create a global variable in the module:


    Public g_strTableName As String


    Then put this on List1_Click event:
    strTableName = List1.List(List1.ListIndex)

    Then on the frmCustomers Form_Load event use this variable:

    strSQL = "Select * From " & g_strTableName

    Regards,


    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819




    [This message has been edited by Serge (edited 11-09-1999).]

Posting Permissions

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



Click Here to Expand Forum to Full Width