Populate EMP_ID control with selection from EMP_NAME control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KMEscherich
    New Member
    • Jun 2007
    • 69

    #1

    Populate EMP_ID control with selection from EMP_NAME control

    Platform = Windows
    Program = Access 2003


    Hi there, I am stumpped!!

    I am attempting to populate a form control as follows:

    I have a form that has 2 drop-down boxes. One retrieves the EMP_ID and the 2nd one retrieves the EMP_NAME and EMP_ID.

    When I make a selection from the EMP_ID control, the data in the database appears accordingly. When I make a selection from the EMP_NAME control, the data in the database appears accordingly, as well.

    I am attempting to have it so when I make a selection from the EMP_NAME control, the EMP_ID control becomes populated with the EMP_ID that corresponds to the selection that I make using the EMP_NAME control.



    RowSource for EMP_NAME
    SELECT distinct T_EMPLOYEE_2.EM P_NAME , T_EMPLOYEE_2.EM P_ID FROM T_EMPLOYEE_2 ;



    [Code=VBA]
    Private Sub Cmd_EmpName_Cli ck()
    Dim rs As Recordset

    Set rs = Me.Recordset.Cl one
    rs.FindFirst "[EMP_NAME] = '" & Combo_EmpName.V alue & "' "
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub
    [/Code]

    =============== =============== =============== ====

    Rowsource for EMP_ID
    SELECT DISTINCT T_EMPLOYEE_2.EM P_ID FROM T_EMPLOYEE_2;



    [Code=VBA]
    Private Sub Cmd_EmpID_Click ()

    Dim rs As Recordset

    Set rs = Me.Recordset.Cl one
    rs.FindFirst "[EMP_ID] = '" & Combo_EmpID.Val ue & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub
    [/Code]

    When I run them independently of each other, they work just fine, but I need to have the EMP_ID control be populated with the EMP_ID when a selection is made from the EMP_NAME form control and also have the EMP_NAME control populate accordingly when a selection is made from the EMP_ID form control.

    I hope I have supplied enough information and have explained it clearly enough for someone to help me.

    Can someone please help me with this???

    Thank you VERY MUCH for your assistance.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    This all sounds like an overcomplicatio n. A single ComboBox with both items in it is fully referenceable from code. There is no "valid" reason I can see why you would want to set them up as you have.

    Having said that, the way to do it would be to set the value of the "other" ComboBox whenever one has an item selected.

    Travel this path and expect problems though.

    Comment

    Working...