Question : How to determine combobox listindex of a known ID

If I'm entering a form "cold", knowing only the IDnumber (IDnumber is in the bound column=column 1) of the record that I want to display in the combo box, how do I make that record appear in the combo box using VB in the Form_Open event.

The combo box has two columns.
Column 1 is zero width, so does not appear, but contains the IDnumber
Column 2 displays a calculated (text) field (lastname + ", " + firstname)

Do I need to determine the ListIndex of the record I'm after?  If so, how do I do this?

Restated: Combo Box should contain the desired name as the Form Opens.  I only have the IDnumber to work with in VB Form_Open event code.

Answer : How to determine combobox listindex of a known ID


use the load event of form

private sub form_load()
dim lngId as long, j
lngID=IDnumber   'don't know how you got the value of IDnumber
with me.cbo1
   for j =0 to .listcount -1
       if .column(0,j)=lngID then
           .value=.itemdata(j)
           exit for
       end if
  next
end with

end sub
Random Solutions  
 
programming4us programming4us