Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    26

    Unanswered: Using a Combo Box to Search for Employee records

    I created a Database table in MS Access 2000.I also have Text Boxes and a Combo box on a Vb 6 Form. I intend to store the names of Employees in the Combo box.
    I connected the Text boxes on the Form to the Database through ADO control which I placed on the Form.

    I want the user to be using the Combo box to search Employee records. When the user selects an employee name from the Combo box, the records of the employee whose name is selected from the Combo box should be displayed automatically in the Text boxes placed on the Vb6 Form.

    I prefer this method to Using "Find method".

    I have tried many codes, but none has worked.

    Please kindly help me.

    Thank you.

    Akinyemi

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    I would recommend that you use ADO, and NOT ado data controls or DAO.

    Ref this ADO Tutorial at a VB sister site.

    Since you wish to only load the single employee record, open a recordset using SELECT * FROM YOURTABLENAME WHERE EMPLOYEENAMEFIELD = ' & cmbEmployees.Text & "'"

    When the recordset opens, assuming that you have an array of textboxes - one for each field in the table, named txtEmployee

    Code:
    Dim N as Integer
    For N = 0 to rs.Fields.Count-1
      Me.txtEmployee(N).Text = "" & rs.Fields(N).Value
    Next N
    Note that the employee textbox control array must begin with zero, and each control array element (index) must match the corresponding field position in the table

    Post your code (after reviewing the tutorial and trying the above suggestions,) along with any problems that you're experiencing, and we'll be glad to help out.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

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