An example how to do this.
I have an Access app where is a form fmDevices, with tblDevices as Record Source;
On this form, I have an unbound combo box control cbbSelectDevice, to locate a record in table tblDevices, and activate this record in form fmDevices. As the combo is unbound, the control source of combo is empty. The Record Source of combo is a query:
Code:
SELECT a.DeviceID, a.DeviceID & "; " & Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & Trim(Nz(a.Producer,"") & " " & IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) AS DeviceInfo FROM tblDevices AS a, tblUsers AS b WHERE (((a.CurrUL)=Forms!fmMain!sfDeviceGrouping!cbbUserLevel Or (a.CurrUL)<IIf(Forms!fmMain!sfDeviceGrouping!cbbUserLevel=99,89,0)) And ((b.TabN)=a.CurrUser) And ((Left(a.DeviceID,2))=Forms!fmMain!sfDeviceGrouping!txtDevGroup)) ORDER BY 2;
(The form fDevices is a source of subform sfDevices, which is a control of another form, which is used to limit the list of devices available to certain group of devices - because this the query the combo is based on is quite complex. User sees 2nd column of query in combo, the width of 1st column - which is the bound one - is set to 0.);
The AfterUpdate event of combo runs a VBA procedure (NB! My advice is, use VBA procedures instead of macros - you have more control about what you do then!):
Code:
Private Sub cbbSelectDevice_AfterUpdate() ' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[DeviceID] = '" & Me![cbbSelectDevice] & "'"
Me.Bookmark = rs.Bookmark
End Sub
NB! The DeviceID PK in this table is a text field - because this apostrophes are used, to enclose the combo value in procedure. In case numeric ID is used (e.g. autonumeric one), those must be omitted!