Populate Combo Box using DLookup

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
Hi, I'm using Access 2010. I have a form with two combo boxes: one is for the employee ID and the other is the employee name. I want the user to be able to input the employee ID (if they know it) and have the employee name populate after update in the employee name combo box. Alternatively, if the user doesn't know the employee ID, I'd like the user to select the employee name and have the employee ID populate after update in that corresponding combo box.

First, I'm just starting with employee ID selection to see if I can get this to work. The DLookup is working correctly. I tested it by setting a msgbox to return the results. However, the value the msgbox returns is not populating in the combo box for some reason. Any ideas?



Code:
Dim varX As Variant
   
    varX = DLookup("EMPLOYEE_FULL_NICK_NAME", "tbl_EMPLOYEE_COST_CENTER_MAP", "EMPLOYEE_ID = '" & Forms![frm_SALES_EMPLOYEE_MANAGEMENT]!cmbEMPLOYEE_ID & "'")
    
    Me.cmbEMPLOYEE_NICKNAME = varX

<!--
Code:
-->
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You don't want to set the value of a combo box, you want to set its row source.
Me.cmbEMPLOYEE_NICKNAME.Rowsource = varX
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top