List Box Search

I am developing in Access 2003. I have a form that has a record set associated to it. It allows you to edit one record at a time through text boxes for each field. To this form I added a list box (lstInstruments) from a query of the same table that the form is linked to.

In the AfterUpdate event of the list box I entered the following code.

Set rs = Me.Recordset.Clone
rs.FindFirst "[InstrumentID] = " & Str(Me![lstInstruments])
Me.Bookmark = rs.Bookmark

This allows me to have a list of all of the records on the form, select one in the list box and then the detail part of the form updates to the correct record.

Now I need to do the reverse. When I click on the record navigator buttons and move from record to record, I need to have the the ListIndex of the list box updated so that the proper record is highlighted in the list box. Is there a way to search the items in the list box to find the item where the the first column = [InstrumentsID] or do I have to go create a recordset of the same query that sources the list box a walk through those records one at a time with a counter to "calculate" the index number.



Answer this question

List Box Search

  • goozbee

    Hello Roger,

    I think I get what you mean. Does the order of the records matter, because if you use the same ordering for the items in the listbox and the records browsed with the form then you could use that to simplify the synchronisation between the record displayed in the form and the currently selected item in the list box.

    You could also handle the events raised by the navigator button and, for example for the next record, just increment the selected index of the list box. That would be a very easy approach.

    I hope that was helpful and was what you where looking for.



  • gbrot

    I figured it out. Put this is the Current event of the main form.

    Me.lstInstruments.Value = Me.InstrumentID


  • ridvan

    :D easy as that! :D

  • List Box Search