When you want to select a single value in a situation like this, a combo box
is a better control than a list box. It offers the user a better way to look
up values and it is easier for you to code.
The typical way this is done is to use an unbound combo box. Make the row
source of the combo a query that returns the primary key field of you table:
SELECT MyKeyField FROM MyTable;
Then to navigate to the selected record, use the combo box's After Update
event:
With Me.RecordsetClone
.FindFirst "[TableKeyField] = " & Me.MyComboBoxName
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
[TableKeyField] should be the name of the field in your table that is the
primary key of the table.
This line:
.FindFirst "[TableKeyField] = " & Me.MyComboBoxName
assumes [TableKeyField] is a numeric field. If it is a text field, then use
this syntax:
.FindFirst "[TableKeyField] = '" & Me.MyComboBoxName & "'"
--
Dave Hargis, Microsoft Access MVP
tecman said:
I have a form with a listbox and several text boxes. I used the wizard
to design the form with text boxes to show the fields in a table. I
added a listbox to the form using the same table. I want to be able to
click on the record in the listbox and populate the text boxes with the
record selected. Your help is greatly appreciated