There might be another way. What I usually do is this.
1) Create a form based on the table.
2) Delete the key field from the detail section.
3) Create a combo box at the header section to list the key field.
- In the combo box Format property sheet:
- Set the Column Count to 2
- Set the Column Width to 0";5" (feel free to replace 5 with a suitable with to display the cust_name
- Essentially, we have 2 columns, but we hide the first column that contains the cust_id
- By default, Bound Column is 1, so you get the cust_id when you get value using Me.cmbCustomerName
4) Set the form Record Source to the Customer table, eg. tblCustomer.
- In the form Format property sheet, also set Record Selectors and Navigation Buttons to No
5) In the form load event, set the record source for the combo box and the form. Something like this:
Code:
With Me.cmbCustomerName
.RowSource = "SELECT cust_id, cust_name FROM tblCustomer"
.Value = .ItemData(0) 'Select the first item
.Requery
End With
'Here, we refresh the form detail based on selection of the combo box
Me.Filter = "tblCustomer.cust_id='" & Me.cmbCustomerName & "'"
Me.FilterOn = True
Me.OrderBy = "cust_name"
Me.OrderByOn = True
Me.Requery
6) In the combo box click event, add something similar.
Code:
'Here, we refresh the form detail based on selection of the combo box
Me.Filter = "tblCustomer.cust_id='" & Me.cmbCustomerName & "'"
Me.FilterOn = True
Me.OrderBy = "cust_name"
Me.OrderByOn = True
Me.Requery
NOTE: Replace table name and column name with the ones you use.