Listbox Click problem (1 Viewer)

wh00t

Registered User.
Local time
Today, 05:39
Joined
May 18, 2001
Messages
264
I have a strange listbox problem, I have simplified what I am doing so no red herrings are there.

I have a form with an unbound listbox (multi select is set to None), there are 4 columns.
For the click event I have MsgBox Me.Listbox.Column(0)

I have 2 entries in the listbox (1 & 2), when I click on '1' in the listbox I get a message of 1 and 2 when I click on '2' as you would expect.

Here's the problem, every now and then after I click on '1' and then click on '2' the message shows 1 and when I click back on '1' the message shows 2. So the message is showing the value of the previous click.
There appears to be no reason for this and looks as though it is a random thing.

The code I want to run is a little more complex and will cause problems if it triggers for the previously selected item.

Has anyone had this problem before or are aware of a way to avoid it?

I am running Access 2003 and have tried this on XP SP3, Vista 32, Win7 64.
 

Datagopher

Data Gopher Dan
Local time
Yesterday, 21:39
Joined
Dec 11, 2008
Messages
43
I remember running into something like this a little while back and I ended up using an iteration like below.

Code:
Dim ctl As Control
Dim var As Variant
Dim strValue As String
Set ctl = Me!MyListbox
For Each var In ctl.ItemsSelected
    strValue = ctl.ItemData(var)
Next var

It was kind've a workaround but it solved the problem.

Dan
Access Development



I have a strange listbox problem, I have simplified what I am doing so no red herrings are there.

I have a form with an unbound listbox (multi select is set to None), there are 4 columns.
For the click event I have MsgBox Me.Listbox.Column(0)

I have 2 entries in the listbox (1 & 2), when I click on '1' in the listbox I get a message of 1 and 2 when I click on '2' as you would expect.

Here's the problem, every now and then after I click on '1' and then click on '2' the message shows 1 and when I click back on '1' the message shows 2. So the message is showing the value of the previous click.
There appears to be no reason for this and looks as though it is a random thing.

The code I want to run is a little more complex and will cause problems if it triggers for the previously selected item.

Has anyone had this problem before or are aware of a way to avoid it?

I am running Access 2003 and have tried this on XP SP3, Vista 32, Win7 64.
 

wh00t

Registered User.
Local time
Today, 05:39
Joined
May 18, 2001
Messages
264
Datagopher: I have tried this but it still misbehaves.

JANR: That post is for a different problem, their code was never set to access the values of the listbox correctly and they did not have the issue of selecting an item but loading the values of the previously selected item.
 

Datagopher

Data Gopher Dan
Local time
Yesterday, 21:39
Joined
Dec 11, 2008
Messages
43
Really? Have you tried clearing out the variable before running it? e.g. strValue="" then go into your code to get the value.

Dan
Access Development

Datagopher: I have tried this but it still misbehaves.

JANR: That post is for a different problem, their code was never set to access the values of the listbox correctly and they did not have the issue of selecting an item but loading the values of the previously selected item.
 

wh00t

Registered User.
Local time
Today, 05:39
Joined
May 18, 2001
Messages
264
Yes, it was how the code was set before this issue was discovered, now I just get it to tell me the value it thinks is there when you click it.


Really? Have you tried clearing out the variable before running it? e.g. strValue="" then go into your code to get the value.

Dan
Access Development
 

Datagopher

Data Gopher Dan
Local time
Yesterday, 21:39
Joined
Dec 11, 2008
Messages
43
That should work. Could you upload a stripped down version of your db with that form and the code?

Dan
Access Development

Yes, it was how the code was set before this issue was discovered, now I just get it to tell me the value it thinks is there when you click it.
 

wh00t

Registered User.
Local time
Today, 05:39
Joined
May 18, 2001
Messages
264
to throw something else in the mix.
I created a new form with just the list box and code in, it works fine!

The form where the list is placed, it is on a tab control. I recreated the form from scratch and it still misbehaves.

Could this be one of those access oddities?
 

Datagopher

Data Gopher Dan
Local time
Yesterday, 21:39
Joined
Dec 11, 2008
Messages
43
It can be a number of different things. As I'm sure you know, just the smallest little thing can cause issues, sometimes it helps to have a second set of eyes to look at it. That's why I asked if you could upload it, it would make it easier to figure out what's going on.

Dan
Access Development

to throw something else in the mix.
I created a new form with just the list box and code in, it works fine!

The form where the list is placed, it is on a tab control. I recreated the form from scratch and it still misbehaves.

Could this be one of those access oddities?
 

Users who are viewing this thread

Top Bottom