By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

Listbox value does not change

P: n/a
ken
Hi,
Say I have a list box. I also created a control on a form bound to that
list box. When I click different rows in the listbox the control
changes the ID of the row depending on what I click.

One thing I'm doing is setting the .selected(i) property of the list
box to true. On the screen I see that a different row gets hillighted,
but the bound control on the form is showing the wrong value?

So changing what is selected with code did not turn out to be the same
as cliking on the list box? Does this make any sense?

Dec 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Absolutely.
Perhaps you could explain "created a control on a form bound to that
list box."
as this might not mean the same thing to all of us
and/or
posting any code that you may be using to effect this binding would
help.

Dec 17 '05 #2

P: n/a
ken wrote:
Hi,
Say I have a list box. I also created a control on a form bound to that
list box. When I click different rows in the listbox the control
changes the ID of the row depending on what I click.

One thing I'm doing is setting the .selected(i) property of the list
box to true. On the screen I see that a different row gets hillighted,
but the bound control on the form is showing the wrong value?

So changing what is selected with code did not turn out to be the same
as cliking on the list box? Does this make any sense?

The mouse click should set your Selected property. One thing you might
want to consider is if you have ColumnHeading set to true. That offsets
you row count by 1.
Dec 17 '05 #3

P: n/a
ken
Hi,
Thanks for your reply.
Um..The control I'm refering to is a text box. Its Control Source is
=[LBox].Value

Here is how I change the selected property of the list box LBox:

For i = 0 To LBox.ListCount() - 1
If LBox.Column(0, i) = Me.pkItem Then
LBox.Selected(i) = True 'this changes the highlited value in the
list box
End If
Next
By the way this is a single select list box..can only select one thing.

Anyhow after that loop I see a change in the highlited row. So before I
had row 5(LBox.Value = 5) selected, after I had row 3 (LBox.Value = 3)
selected.

However my textbox tells me that I still have Row 5 (LBox.Value = 5)
selected?

Dec 17 '05 #4

P: n/a
ken
No that's not the issue...no offset. I'm talking about where a
different item gets selected, but the LBox.Value is still the old one...

Dec 17 '05 #5

P: n/a
On 17 Dec 2005 14:25:54 -0800, "ken" <ge****@gmail.com> wrote:
Hi,
Say I have a list box. I also created a control on a form bound to that
list box. When I click different rows in the listbox the control
changes the ID of the row depending on what I click.

One thing I'm doing is setting the .selected(i) property of the list
box to true. On the screen I see that a different row gets hillighted,
but the bound control on the form is showing the wrong value?

So changing what is selected with code did not turn out to be the same
as cliking on the list box? Does this make any sense?


Lyle is being particularly kind.

But, translating with a crystal ball, I guess that you have a bound
multi-select listbox. The list box can have multiple items selected.
The field that the listbox is bound to can only store one result.
Hence, a bound multi-select listbox is destined for confusion.

I'm not even sure why Access allows multi-select list boxes to be
bound. Endless confusion results.

You will need to walk the items of the listbox to determine whether
each is selected and then use the results accordingly, probably by
storing the value of each selected item somehow.

But I am just guessing.

mike

Dec 17 '05 #6

P: n/a
ken
Actually I have a single select list box...not multiselect!

Dec 17 '05 #7

P: n/a
Sometimes code like this doesn't run when it is in an event procedure.
We think the event has been fired because we have done something in
code. But it is not fired when do something in code.
To know if this might be a problem causing the behaviour you describe,
we need to know if this code lives in an event procedure, and if so,
which one.

Dec 18 '05 #8

P: n/a
ken
Its in the OnClick event for a command button. The function of the
command button is to 1. Change the selection in the List Box, and 2. To
refresh another Listbox in the form. Since the second list box depends
on the selected value of the first listbox, it would be nice for the
actual value of the first listbox to be updated when you change the
..selected property.

Thank you.

Dec 18 '05 #9

P: n/a
On 17 Dec 2005 14:57:17 -0800, "ken" <ge****@gmail.com> wrote:
Hi,
Thanks for your reply.
Um..The control I'm refering to is a text box. Its Control Source is
=[LBox].Value

Here is how I change the selected property of the list box LBox:

For i = 0 To LBox.ListCount() - 1
If LBox.Column(0, i) = Me.pkItem Then
LBox.Selected(i) = True 'this changes the highlited value in the
Insert here:

LBox.Value = LBox.Column(0, i)

mike
list box
End If
Next
By the way this is a single select list box..can only select one thing.

Anyhow after that loop I see a change in the highlited row. So before I
had row 5(LBox.Value = 5) selected, after I had row 3 (LBox.Value = 3)
selected.

However my textbox tells me that I still have Row 5 (LBox.Value = 5)
selected?

Dec 18 '05 #10

P: n/a
ken
That did it...thank you.

Dec 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.