Go to beginning of list when list box selections are cleared

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