Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    34

    Unanswered: Using combo boxes to Lookup values in table

    Hi all,

    I have a question on what seems to be an easy task. I need the code for Visual Basic to lookup values in a table using a combo box.

    I have an Access Database with a Department table in it. What would be the code to tell VB to select all values in flddepartment from tbldepartment? I am using VB 6.0 and Access 2000.

    Thanks,
    JC

  2. #2
    Join Date
    Oct 2005
    Posts
    178

    Wink

    Quote Originally Posted by jcoe
    Hi all,

    I have a question on what seems to be an easy task. I need the code for Visual Basic to lookup values in a table using a combo box.

    I have an Access Database with a Department table in it. What would be the code to tell VB to select all values in flddepartment from tbldepartment? I am using VB 6.0 and Access 2000.

    Thanks,
    JC
    SQLStatement = "SELECT * From tbldepartment WHERE flddepartment ='" & cbodepartment.text & "'"

  3. #3
    Join Date
    Jul 2004
    Posts
    34
    Thanks for the post Fredservillon, but can you please explain further? I don't believe I need a WHERE statement because I want to select all rows in tbldepartment. Also, do I need to give the combo box some properties to find the database? I have a data control but it is set to sort on record. Let me know if you have any questions.

    Thanks,
    JC

  4. #4
    Join Date
    Oct 2005
    Posts
    178

    Wink

    Ok, Assuming yur fldDeprtment records are unique you can use Data COmbo object for your drop down list.
    This will give a drop down list of department names from your department table for user to select. I hope that's what you meant


    Code:
    Set adoDepartment = New Recordset
    With adoDepartment
    .Open "SELECT fldDepartment FROM tblDepartment", CNN, adOpenStatic, adLockOptimistic
    Set dbcDepartment.RowSource = adoDepartment
    dbcDepartment.ListField = "fldDepartment"
    
    end with
    Last edited by fredservillon; 01-18-06 at 22:40.

Posting Permissions

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