"You've used the ListIndex property incorrectly" message

"You've used the ListIndex property incorrectly" message

Post by bXNjZXJ0aW » Fri, 09 May 2008 03:58:01


"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.
 
 
 

"You've used the ListIndex property incorrectly" message

Post by Marshall B » Fri, 09 May 2008 04:23:43


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

--
Marsh
MVP [MS Access]

 
 
 

"You've used the ListIndex property incorrectly" message

Post by bXNjZXJ0aW » Fri, 09 May 2008 04:38:00

Thanks for the response - I am setting the focus in the preceding statement.
 
 
 

"You've used the ListIndex property incorrectly" message

Post by bXNjZXJ0aW » Fri, 09 May 2008 05:07:32

If I code this it always works:

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

"You've used the ListIndex property incorrectly" message

Post by Marshall B » Fri, 09 May 2008 06:34:42

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]
 
 
 

"You've used the ListIndex property incorrectly" message

Post by George Nic » Fri, 09 May 2008 06:53:08

?? Confused.

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

--
HTH,
George
 
 
 

"You've used the ListIndex property incorrectly" message

Post by Marshall B » Fri, 09 May 2008 07:33:25


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.

--
Marsh
MVP [MS Access]
 
 
 

"You've used the ListIndex property incorrectly" message

Post by Graham Man » Fri, 09 May 2008 07:34:20

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
 
 
 

"You've used the ListIndex property incorrectly" message

Post by George Nic » Fri, 09 May 2008 08:11:06

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
 
 
 

"You've used the ListIndex property incorrectly" message

Post by ddddddd » Fri, 09 May 2008 16:13:51