last item in ListBox

G

Gator

OK...for some reason this little code does exactly what I want, that is to be
able to drag the scroll bar on my list box and have the list scroll with it
automatically. I don't know what it is about this code and I hope someone
will enlighten me.

Private Sub Form_Load()
Me.List0.Selected(last) = True
End Sub

And when the Form loads, the First item in the list is selected....????
 
K

Klatuu

last has no meaning.
It means two things.
1. You are not using Option Explicit in your modules. That allows you to
use variable names that have not been dimmed. As you can see, this causes
run time problems. If you had used Option Explicit, you would get a compile
error because last is not dimmed.

2. Whereever you copied the code from, you missed part of it. what you need
to put there is the number of rows in the list box. For that you use the
ListCount property of the listbox -1. You have to subtract 1 because the
items index for a list box is 0 based, so I think this version will solve
your problem:

With Me
.List0.Selected(.List0.ListCount -1) = True
End With
 

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