ListBox Question

  • Thread starter Thread starter Alastair MacFarlane
  • Start date Start date
A

Alastair MacFarlane

Dear All,

Can you programatically select an item in a ListBox based
on the value entered in a text box from the after_update
event? I have tried the following code which does not work:

forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
forms!Form1!MyListBox.value.column(1) = me!Text1.text

The bound column of the ListBox is Column(0). I want the
TextBox to be used to select the Column(1) value.

Thanks for all help...

Alastair MacFarlane
 
Hi,


The assignment operator assign what is to the right to what is to the left. The syntax should have
been


Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)


Also note that in Access, the value is held into the property VALUE, not the property TEXT. A
Value is of data type VARIANT, so it can handle the values NULL without problem. A Text data type
is a STRING and cannot handle a Variant, so, it cannot handle a NULL, which is a frequent value in
databases (outer join, or otherwise). Also, in Access, the Text property is only valid when the
control has the focus, it then hold the data like it is actually typed by the end user, while Value
is the last validated (by the control) value (not necessary saved in the table), and OldValue the
last committed value (in the record, validatated in the table).


If the list box has the possibility to let the user select more than one value (multiselect), you
have to use the ItemData property of the Listbox, after you " point" to the selected row of your
liking (see http://www.mvps.org/access/forms/frm0007.htm, or the help file for more examples on how
to access these data).


Hoping it may help,
Vanderghast, Access MVP
 
Vanderghast,

Thanks for the reply! I am sorry if I am confusing the
issue. What I would like is to enter text in a text box
and the value in the Value property of the TextBox would
highlight itself in column(1) of a ListBox? and not the
other way round. To obtain the value from a selected
ListBox to the TextBox would be straightforward. The
converse does not work.

Forms!Form1!MyComboBox.value.column(1)=Me.Text1.Value

Any suggestions?

Thanks again...

Alastair MacFarlane



-----Original Message-----
Hi,


The assignment operator assign what is to the right to
what is to the left. The syntax should have
been


Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)


Also note that in Access, the value is held into the
property VALUE, not the property TEXT. A
Value is of data type VARIANT, so it can handle the
values NULL without problem. A Text data type
is a STRING and cannot handle a Variant, so, it cannot
handle a NULL, which is a frequent value in
databases (outer join, or otherwise). Also, in Access,
the Text property is only valid when the
control has the focus, it then hold the data like it is
actually typed by the end user, while Value
is the last validated (by the control) value (not
necessary saved in the table), and OldValue the
last committed value (in the record, validatated in the table).


If the list box has the possibility to let the user
select more than one value (multiselect), you
have to use the ItemData property of the Listbox, after
you " point" to the selected row of your
or the help file for more examples on how
to access these data).


Hoping it may help,
Vanderghast, Access MVP


Dear All,

Can you programatically select an item in a ListBox based
 
Vanderghast,

Thanks for the reply! I am sorry if I am confusing the
issue. What I would like is to enter text in a text box
and the value in the Value property of the TextBox would
highlight itself in column(1) of a ListBox? and not the
other way round. To obtain the value from a selected
ListBox to the TextBox would be straightforward. The
converse does not work.

Forms!Form1!MyComboBox.value.column(1)=Me.Text1.Value

Any suggestions?

Thanks again...

Alastair MacFarlane



-----Original Message-----
Hi,


The assignment operator assign what is to the right to
what is to the left. The syntax should have
been


Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)


Also note that in Access, the value is held into the
property VALUE, not the property TEXT. A
Value is of data type VARIANT, so it can handle the
values NULL without problem. A Text data type
is a STRING and cannot handle a Variant, so, it cannot
handle a NULL, which is a frequent value in
databases (outer join, or otherwise). Also, in Access,
the Text property is only valid when the
control has the focus, it then hold the data like it is
actually typed by the end user, while Value
is the last validated (by the control) value (not
necessary saved in the table), and OldValue the
last committed value (in the record, validatated in the table).


If the list box has the possibility to let the user
select more than one value (multiselect), you
have to use the ItemData property of the Listbox, after
you " point" to the selected row of your
or the help file for more examples on how
to access these data).


Hoping it may help,
Vanderghast, Access MVP


Dear All,

Can you programatically select an item in a ListBox based
 
Hi,
Not sure if this is the best way, but it will work:

Dim i As Integer
For i = 0 To Me.List0.ListCount - 1
If Me.List0.Column(1, i) = Me.Text3 Then
Me.List0.Selected(i) = True
End If
Next
 
Back
Top