Selecting value on Listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list box that has 2 columns: ID and Name. The listbox is bound on
column ID. How can I programmatically select the row based on the value of
the Name column ( i.e. I don't know what the ID column is)? thanks in advance
for any help.
 
Although yoy haven't provided enough details of your situation, you may do as
follows:

Suppose:
1) the values of the list box "ListBox1" are taken from a table (or query)
"Table1";
2) the name is entered by the user into text box "TextBox1";
3) the list box value should be updated immediately after the value of
TextBox1 is changed;
4) the name of the form with "ListBox1" and "TextBox1" is "MyForm".

In this case you should set the AfterUpdate property of TextBox1 as follows:

Private Sub TextBox1_AfterUpdate()
Me.ListBox1.Value = DLookup("[ID]", "Table1",
"[Name]=[Forms]![MyForm]![TextBox1]")
End Sub
 
That's exactly what I needed! thank you very much Mike!

Mike said:
Although yoy haven't provided enough details of your situation, you may do as
follows:

Suppose:
1) the values of the list box "ListBox1" are taken from a table (or query)
"Table1";
2) the name is entered by the user into text box "TextBox1";
3) the list box value should be updated immediately after the value of
TextBox1 is changed;
4) the name of the form with "ListBox1" and "TextBox1" is "MyForm".

In this case you should set the AfterUpdate property of TextBox1 as follows:

Private Sub TextBox1_AfterUpdate()
Me.ListBox1.Value = DLookup("[ID]", "Table1",
"[Name]=[Forms]![MyForm]![TextBox1]")
End Sub




Samantha said:
I have a list box that has 2 columns: ID and Name. The listbox is bound on
column ID. How can I programmatically select the row based on the value of
the Name column ( i.e. I don't know what the ID column is)? thanks in advance
for any help.
 
Back
Top