"You've used the ListIndex property incorrectly" message

M

mscertified

"You've used the ListIndex property incorrectly" message

Any idea what causes this message to come from code:

Me!lstReplace.ListIndex = i

i is a long
the value of i is within the listcount
I only get this error sometimes, not every time.
 
M

Marshall Barton

mscertified said:
"You've used the ListIndex property incorrectly" message

Any idea what causes this message to come from code:

Me!lstReplace.ListIndex = i

i is a long
the value of i is within the listcount
I only get this error sometimes, not every time.


Make sure that the list box has the focus when you set
ListIndex.
 
M

mscertified

If I code this it always works:

Me!lstReplace.ListIndex = 1 'Set index to start
Me!lstReplace.ListIndex = i 'Set index position
 
M

Marshall Barton

It would be kind of a basic mistake, but the only other
thing I can think of is that your loop is from 1 to
ListCount. ListIndex is a zero based value so the loop
would go from 0 to ListCount-1 (unless you have ColumnHeads
set to Yes, in which case the loop would be from 1 to
ListCount-1).
 
G

George Nicholson

?? Confused.

ListIndex (for Access Listboxes at least) is Read-only long.

--
HTH,
George


Marshall Barton said:
It would be kind of a basic mistake, but the only other
thing I can think of is that your loop is from 1 to
ListCount. ListIndex is a zero based value so the loop
would go from 0 to ListCount-1 (unless you have ColumnHeads
set to Yes, in which case the loop would be from 1 to
ListCount-1).
--
Marsh
MVP [MS Access]

If I code this it always works:

Me!lstReplace.ListIndex = 1 'Set index to start
Me!lstReplace.ListIndex = i 'Set index position
 
M

Marshall Barton

George said:
?? Confused.

ListIndex (for Access Listboxes at least) is Read-only long.


Help is not perfect :-\

ListIndex can be set if the list/combo bex has the focus.
My A2003 ListIndex Help topic says its Reaf Only, but then
includes an example of how to set it.
 
G

Graham Mandeno

Hi George

No it isn't - not in A2003 at least. You can set it to any value from 0 to
..ListCount-1

Setting it to a value outside this range raises the error that the OP
reported.

Interestingly, setting .ListIndex also raises the Click event.
--
Cheers :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

George Nicholson said:
?? Confused.

ListIndex (for Access Listboxes at least) is Read-only long.

--
HTH,
George


Marshall Barton said:
It would be kind of a basic mistake, but the only other
thing I can think of is that your loop is from 1 to
ListCount. ListIndex is a zero based value so the loop
would go from 0 to ListCount-1 (unless you have ColumnHeads
set to Yes, in which case the loop would be from 1 to
ListCount-1).
--
Marsh
MVP [MS Access]

If I code this it always works:

Me!lstReplace.ListIndex = 1 'Set index to start
Me!lstReplace.ListIndex = i 'Set index position

:

mscertified wrote:

"You've used the ListIndex property incorrectly" message

Any idea what causes this message to come from code:

Me!lstReplace.ListIndex = i

i is a long
the value of i is within the listcount
I only get this error sometimes, not every time.


Make sure that the list box has the focus when you set
ListIndex.
 
G

George Nicholson

ok, I stand corrected.

I know it was writeable in VB5 forms and vividly recall trying to use it in
a similar fashion with Access forms and running headlong into the
"read-only" limitation, so I found an alternative solution for whatever it
was I was trying to do and have treated it as read-only ever since. I just
assumed that it was one of the few differences in how VB forms and Access
forms/controls implemented certain things. This memory goes back to A97
however (maybe it was read-only then??), so I'm making a mental note to
revisit the issue next time it comes up.

--
HTH,
George


Graham Mandeno said:
Hi George

No it isn't - not in A2003 at least. You can set it to any value from 0
to .ListCount-1

Setting it to a value outside this range raises the error that the OP
reported.

Interestingly, setting .ListIndex also raises the Click event.
--
Cheers :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

George Nicholson said:
?? Confused.

ListIndex (for Access Listboxes at least) is Read-only long.

--
HTH,
George


Marshall Barton said:
It would be kind of a basic mistake, but the only other
thing I can think of is that your loop is from 1 to
ListCount. ListIndex is a zero based value so the loop
would go from 0 to ListCount-1 (unless you have ColumnHeads
set to Yes, in which case the loop would be from 1 to
ListCount-1).
--
Marsh
MVP [MS Access]


mscertified wrote:
If I code this it always works:

Me!lstReplace.ListIndex = 1 'Set index to start
Me!lstReplace.ListIndex = i 'Set index position

:

mscertified wrote:

"You've used the ListIndex property incorrectly" message

Any idea what causes this message to come from code:

Me!lstReplace.ListIndex = i

i is a long
the value of i is within the listcount
I only get this error sometimes, not every time.


Make sure that the list box has the focus when you set
ListIndex.
 
D

dddddddd

Graham Mandeno said:
Hi George

No it isn't - not in A2003 at least. You can set it to any value from 0
to .ListCount-1

Setting it to a value outside this range raises the error that the OP
reported.

Interestingly, setting .ListIndex also raises the Click event.
--
Cheers :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

George Nicholson said:
?? Confused.

ListIndex (for Access Listboxes at least) is Read-only long.

--
HTH,
George


Marshall Barton said:
It would be kind of a basic mistake, but the only other
thing I can think of is that your loop is from 1 to
ListCount. ListIndex is a zero based value so the loop
would go from 0 to ListCount-1 (unless you have ColumnHeads
set to Yes, in which case the loop would be from 1 to
ListCount-1).
--
Marsh
MVP [MS Access]


mscertified wrote:
If I code this it always works:

Me!lstReplace.ListIndex = 1 'Set index to start
Me!lstReplace.ListIndex = i 'Set index position

:

mscertified wrote:

"You've used the ListIndex property incorrectly" message

Any idea what causes this message to come from code:

Me!lstReplace.ListIndex = i

i is a long
the value of i is within the listcount
I only get this error sometimes, not every time.


Make sure that the list box has the focus when you set
ListIndex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top