error '7777' trying to set focus on listbox

  • Thread starter Thread starter astro
  • Start date Start date
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
 
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.
 
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.
 
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.
 
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)
 
Back
Top