Results 1 to 3 of 3
  1. #1
    accessLearn is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jul 2015
    Posts
    11

    How to automatically display related value in a text box when a field is selected in a combo box

    I have an employee table TblEmployee with employee id(auto num), name (txt) and role(numeric field)
    I have another table with ID(autonum) and rolename
    I have a form in which I have a combo box to select employee name and a textbox to automatically display role name.
    The rowsource property for the combo box is


    SELECT TblEmployee.EmpId, TblEmployee.EmpName, TblEmployee.Role FROM TblEmployee ORDER BY [EmpName];
    and column width is 0";2";0"
    I have the text box for the role and I want to display role name automatically, so Control Source property for the text box is = CboEmp.column(2)
    where CboEmp is the name of combo box
    but the problem is that it is displaying the number for the role as it is the numeric fiel and I want to display the actual role.
    How can I do that?

    Thanks!!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You could try (untested not sure of syntax???)
    Control Source property for the text box =DLookup("Rolename","tblRole","id = " & CboEmp.column(2))

    Also, as you have doe in tblEmployee EmployeeID, you should consider RoleId in tblRole.
    After a while it's hard to keep the ID's straight when all of the tables have an ID field.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The rowsource property for the combo box is
    SELECT TblEmployee.EmpId, TblEmployee.EmpName, TblEmployee.Role FROM TblEmployee ORDER BY [EmpName];
    and column width is 0";2";0"
    So "TblEmployee.Role" is a number? Is it referenced by any other controls or code? If not then you could change the row source for the combo box .
    Add the table "tblRole" to the SQL (linked PK to FK), delete the column "TblEmployee.Role", add a column for "tblRole.RoleName".

    Something like
    Code:
    SELECT TblEmployee.EmpId, TblEmployee.EmpName, TblRole.RoleName 
    FROM tblRole INNER JOIN TblEmployee ON tblRole.RoleID_PK = TblEmployee.Role_FK
    ORDER BY [EmpName]
    I always name my PK and FK field with a suffix ... change the names as required. Keeps me from getting confused (most of the time )

    Shouldn't need any other changes.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-22-2014, 09:44 AM
  2. Replies: 8
    Last Post: 06-26-2014, 08:52 AM
  3. Replies: 1
    Last Post: 07-26-2013, 12:20 PM
  4. Replies: 3
    Last Post: 10-13-2011, 04:42 PM
  5. Replies: 11
    Last Post: 01-06-2010, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums