error '7777' trying to set focus on listbox

A

astro

I have the following code:

If cboLocation.ListCount > 1 Then
Me.cboLocation.SetFocus
Me.cboLocation.ListIndex = 1
End If

which generates the "using listindex property incorrectly" error message.

- combo box is enabled
- error occurs on listindex line
- this should work but doesnt'

any ideas?

Thanks
 
K

Ken Snell [MVP]

Using a value of 1 for the ListIndex means that you're trying to set the
combo box to the second item in the dropdown list (ListIndex is a zero-based
property). Use a value of 0 to set the combo box to the first item in the
list.

Do you have two items in the list? If you have only one item, the error that
you see will occur.
 
S

Stephen Lebans

Another possibility Ken is that the are calling that code from the
Form's Open event. THe Combo control isnot fully instantiated in that
event. I have even seen this method fail in the form's Load event.
To set a default value use the DefaultValue prop.

--

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

Ken Snell [MVP]

Good point!

--

Ken Snell
<MS ACCESS MVP>

Stephen Lebans said:
Another possibility Ken is that the are calling that code from the
Form's Open event. THe Combo control isnot fully instantiated in that
event. I have even seen this method fail in the form's Load event.
To set a default value use the DefaultValue prop.

--

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

astro

Thanks - I'll take your feedback and look at it - i did finially settle on
the following code (which works)....

Me.cboLocation = Me.cboLocation.ItemData(1)
 

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