ListIndex on ListBox with Error Code 7777

R

Ronald Dodge

Using AC02, SP2, VBA 6.3 on W2K, SP4

What's the deal with such a confusing help file with regards to the
ListIndex Property? On the one hand, it shows in 2 different places (at the
top with "Read/Write" and at the bottom with the example) that the property
can be written to via code, but yet, it also states that the property is
read-only (in the second paragraph under "Remarks" section). Here's the
link to the help file online:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac10/htm
l/acprolistindex.asp

When I attempt to set this property, it gives me the error code, "7777",
with the statement, "You've used the ListIndex Property incorrectly." When
I click on the "Help" button, the help file only brings up a blank grey
page.

What I am attempting to do, set which item is the active item as it's shown
via the ListIndex property of a Listbox, as the code shows below, which is
within the MouseMove Event:

Dim CurItem As Long
CurItem = Int((Y - 1) / TPI)
If CurItem < Me.lbxDLU.ListCount And CurItem > -1 Then
Me.lbxDLU.ListIndex = CurItem 'This is the line it errors out on.
Else
Me.lbxDLU.ListIndex = -1
End If

The "TPI" variable is how many twips there are per record including the line
spacing or Twips Per Item.

Here's another link to another example of using the ListIndex property to
select an item within the listbox (or combobox).

http://support.microsoft.com/default.aspx?scid=kb;en-us;209853

The only remote possibility that I could think of, does the control have to
be bound to a table for this property to be written to?
 
S

Stephen Lebans

The control MUST have the focus in order for you to write to the
ListINdex prop.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
S

Sandra Daigle

Hi Ronald,

Have you tried setting focus to the listbox? I believe that the listbox must
have the focus before you can assign a value using the listindex property.
 
R

Ronald Dodge

Thank you for the explanation as that clearifies why I had the issue. Just
wish the help file would have stated that too, which is about the only
advantage that 97 has over the later versions, help files explains a lot
better in the majority of the cases.
 
R

Ronald Dodge

Thank you for the info and taking the time to respond as that's what Stephan
Lebans mentioned too and I didn't realize it until after I saw his message.
Would have been nice had the help file mentioned it. It also would have
been nice for the ListIndex Property to be used without it necessarily
selecting that item and deselecting all other selected items, so I will have
to put in a work around for the drag and drop type feature that I'm
attempting to do for both, keyboard and mouse users, thus the majority of
the coding for this task is going in a class module.

--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
Sandra Daigle said:
Hi Ronald,

Have you tried setting focus to the listbox? I believe that the listbox must
have the focus before you can assign a value using the listindex property.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Ronald said:
Using AC02, SP2, VBA 6.3 on W2K, SP4

What's the deal with such a confusing help file with regards to the
ListIndex Property? On the one hand, it shows in 2 different places
(at the top with "Read/Write" and at the bottom with the example)
that the property can be written to via code, but yet, it also states
that the property is read-only (in the second paragraph under
"Remarks" section). Here's the link to the help file online:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac10/htm
l/acprolistindex.asp

When I attempt to set this property, it gives me the error code,
"7777", with the statement, "You've used the ListIndex Property
incorrectly." When I click on the "Help" button, the help file only
brings up a blank grey page.

What I am attempting to do, set which item is the active item as it's
shown via the ListIndex property of a Listbox, as the code shows
below, which is within the MouseMove Event:

Dim CurItem As Long
CurItem = Int((Y - 1) / TPI)
If CurItem < Me.lbxDLU.ListCount And CurItem > -1 Then
Me.lbxDLU.ListIndex = CurItem 'This is the line it errors out
on. Else
Me.lbxDLU.ListIndex = -1
End If

The "TPI" variable is how many twips there are per record including
the line spacing or Twips Per Item.

Here's another link to another example of using the ListIndex
property to select an item within the listbox (or combobox).

http://support.microsoft.com/default.aspx?scid=kb;en-us;209853

The only remote possibility that I could think of, does the control
have to be bound to a table for this property to be written to?
 

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