Go to beginning of list when list box selections are cleared

K

KarenB

I have the following code on the OnClick event of a command button, which
works great in clearing all of the selections from the list box, but I want
to end up at the beginning of my list after this runs, rather then the end.
How do I do that?

Private Sub cmdClearMe_Click()

Dim lngListCnt As Long
lngListCnt = Me.lstAccountName.ListCount - 1
For CNTR = 0 To lngListCnt
Me.lstAccountName.Selected(CNTR) = False
Next CNTR

End Sub
 
M

Mr. B

KarenB,

Someone else may have a more elegant way of doing this but try this code:

Dim strSql As String
Dim lngListCnt As Long
Dim cntr
lngListCnt = Me.lstAccountName.ListCount - 1
For cntr = 0 To lngListCnt
Me.lstAccountName.Selected(cntr) = False
Next cntr
strSql = "Insert the Sql statement that populates your list box here;"
With Me.lstAccountName
.RowSource = strSql
.Requery
End With

I used some concatenation to try to not have wraping of the code.
Copy the SQL statement that you are using to populate your listbox and place
it in the code where indicated.
 
K

KarenB

That's perfect! Thank you!

Mr. B said:
KarenB,

Someone else may have a more elegant way of doing this but try this code:

Dim strSql As String
Dim lngListCnt As Long
Dim cntr
lngListCnt = Me.lstAccountName.ListCount - 1
For cntr = 0 To lngListCnt
Me.lstAccountName.Selected(cntr) = False
Next cntr
strSql = "Insert the Sql statement that populates your list box here;"
With Me.lstAccountName
.RowSource = strSql
.Requery
End With

I used some concatenation to try to not have wraping of the code.
Copy the SQL statement that you are using to populate your listbox and place
it in the code where indicated.
 

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