Pre-selecting dropdown list item

  • Thread starter Thread starter CrystalDBA
  • Start date Start date
C

CrystalDBA

I have two combo dropdown lists controls.

One lists the employees and the other lists the team leaders. For
each project, an employee has a team leader.

If an employee is selected in combobox #1, I want to pre-select the
team leader in combobox #2. There are 4 team leaders. I still want
all 4 to show, I just want to pre-select the item.

I have an employee table
========================
employeeid, employeename, teamleaderid

Team Leaer table
================
teamleaderid, teamleader

EmployeeTeamLeader
==================
Teamid, employeeid, teamleaderid

Currently, combox#1 shows lists of employees. Combox#2 shows list of
teamleaders. Great. But how do I preselect the teamleader (using the
employeeteamleader)?

Thanks,

Tony
 
I am guessing that the Team Leader combo box is a 2 column box and that the
"teamleaderid" is the bound column and that the Employee combo box is also a
2 column box with "employeeid" as the bound column.

I'm a little confused with the "teamleaderid" in the Employee table since
you have the EmployeeTeamLeader table. However, you would try something like
this in the AfterUpdate event of the Employee combo box.

Me.cboTeamLeader = DLookup("[teamleaderid]", "EmployeeTeamLeader",
"[employeeid]=" & Me.cboEmployee)

If the ID is text instead of numeric, change the above to:

Me.cboTeamLeader = DLookup("[teamleaderid]", "EmployeeTeamLeader",
"[employeeid]='" & Me.cboEmployee & "'")

Another possibility, if the employee combo is a 3 column and you already
have the team leader in it is to refer to the team leader column.

Me.cboTeamLeader = Me.cboEmployee.Column(2)
The Column property is zero based so 2 would be the 3rd column.
 
CrystalDBA said:
I have two combo dropdown lists controls.

One lists the employees and the other lists the team leaders. For
each project, an employee has a team leader.

If an employee is selected in combobox #1, I want to pre-select the
team leader in combobox #2. There are 4 team leaders. I still want
all 4 to show, I just want to pre-select the item.

I have an employee table
========================
employeeid, employeename, teamleaderid

Team Leaer table
================
teamleaderid, teamleader

EmployeeTeamLeader
==================
Teamid, employeeid, teamleaderid

Currently, combox#1 shows lists of employees. Combox#2 shows list of
teamleaders. Great. But how do I preselect the teamleader (using the
employeeteamleader)?


Set the employee combo to 3 columns and set its RowSource to
a query that retrieves all 3 fields in the table:
SELECT employeeid, employeename, teamleaderid
FROM employeetable
ORDER BY employeename

Then you can use the combo's AfterUpdate event to just set
the leader combo's value
Me.cboLeaer = Me.cboemployee.Column(2)

You may want to add a check if the leader combo has already
been set and not change it if it is.
 
Thanks Marshall and Wayne! That helped out tremendously.

Tony





Wayne Morgan said:
I am guessing that the Team Leader combo box is a 2 column box and that the
"teamleaderid" is the bound column and that the Employee combo box is also a
2 column box with "employeeid" as the bound column.

I'm a little confused with the "teamleaderid" in the Employee table since
you have the EmployeeTeamLeader table. However, you would try something like
this in the AfterUpdate event of the Employee combo box.

Me.cboTeamLeader = DLookup("[teamleaderid]", "EmployeeTeamLeader",
"[employeeid]=" & Me.cboEmployee)

If the ID is text instead of numeric, change the above to:

Me.cboTeamLeader = DLookup("[teamleaderid]", "EmployeeTeamLeader",
"[employeeid]='" & Me.cboEmployee & "'")

Another possibility, if the employee combo is a 3 column and you already
have the team leader in it is to refer to the team leader column.

Me.cboTeamLeader = Me.cboEmployee.Column(2)
The Column property is zero based so 2 would be the 3rd column.

--
Wayne Morgan
Microsoft Access MVP


CrystalDBA said:
I have two combo dropdown lists controls.

One lists the employees and the other lists the team leaders. For
each project, an employee has a team leader.

If an employee is selected in combobox #1, I want to pre-select the
team leader in combobox #2. There are 4 team leaders. I still want
all 4 to show, I just want to pre-select the item.

I have an employee table
========================
employeeid, employeename, teamleaderid

Team Leaer table
================
teamleaderid, teamleader

EmployeeTeamLeader
==================
Teamid, employeeid, teamleaderid

Currently, combox#1 shows lists of employees. Combox#2 shows list of
teamleaders. Great. But how do I preselect the teamleader (using the
employeeteamleader)?

Thanks,

Tony
 
Back
Top