list box selecting record on form

D

Dan

I have a list box that is connected to a table that has a primary key that is
made up of two fields (key1, key2). WHen you click on it the form goes to
that record. However, right now the vba code looks like:

' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[key1] = " & Chr(34) & Me![List101] & Chr(34)
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Right now if there is multiple key1 values it just goes to the first record.
How can I add key2 in?
 
D

Douglas J Steele

Assuming that the key1 value is the bound column, and that key2 is the 2nd
column in the combo box, try

rs.FindFirst "[key1] = " & Chr(34) & Me![List101] & Chr(34) & " And [key2] =
" & Chr(34) & Me![List101].Column(1) & Chr(34)
 
Top