Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position to first item in ListBox - Access 2000

Status
Not open for further replies.

KMITCH

MIS
May 1, 2000
42
0
0
US
Hello,

I am using some VBA to iteratively load selected items from a ListBox into a parameter table. After the VBA finishes executing, the focus of the ListBox seems to be on the final record.

Is there an easy VBA way to reset the focus to the first ListBox item while not accidentally deselecting any of the selected items?

Thanks,
Keith
 
Could you provide the section of code that loads the list box items into the table?
 
Sure,

After reviewing, am seeing that it is not the load or the check and clear all that is scrolling to the end of the list box. I would just like to automatically move back to the beginning of the list as a cleanup.

The code below is not the load I referenced earlier.

--------------------------------
Private Sub chkClearAll_Click()
If Me!chkClearAll = True Then
Me!chkSelectAll = False
Call chkSet(False)
End If
End Sub
--------------------------------
Private Sub chkSet(DoCheck As Boolean)
Dim ctlSource As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = Me!lstPolicy
For intCurrentRow = ctlSource.ListCount - 1 To 0 Step -1
ctlSource.Selected(intCurrentRow) = DoCheck
Next intCurrentRow

End Sub
----------------------------------------
 
Private Sub chkClearAll_Click()
If Me!chkClearAll = True Then
Me!chkSelectAll = False
Call chkSet(False)
End If
lstPolicy.MoveFirst '
End Sub
 
Thanks, but the MoveFirst doesn't seem to want to work in this situation. I think that it would work if this was a normal record set but a list box seems to behave differently.

Keith
 
Me!lbxWhatever.Selected(0) = True

works for me. Does it work in your situation?

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Thanks Jeremy,

It does work to set the first item in the list box to "selected" but does not work to cause the listbox to scroll back to the top. My list is longer than the listbox, so am having trouble redisplaying the top of the list.

Thanks,
Keith
 
Finally found the answer...

Since I was using a checkbox to fire off the code, the focus had moved away from the listbox. The following works:

Me!lstPolicy.SetFocus
Me!lstPolicy.ListIndex = 0

Thanks, everyone, for your help.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top