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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a listbox then moving to that row in the list via VBA 1

Status
Not open for further replies.

MrMode

Technical User
Aug 28, 2003
195
GB
My list is sorted in ascending value. It is populated via sqlstr in vba that pulls down each row in a table, then sorts them in ascending value order. The list can be 'added to' with values collected from several text boxes that are then inserted into a table and the list requeried.

I want to find the find the last record in a table, then move to that record in the sorted list and 'select' it.

This appears to work. The row with the values is identified and 'selected', but when I test the value of the bound column it is null.

Code:
Dim lastPlaceID As Integer

lastPlaceID = DMax("PrizeSlidingScalePlacesID", "tblPrizeSlidingScalePlaces")
' or = DMax("IDField","YourTable","WhenField=Value")

    Dim i As Integer
    
        For i = 0 To Me.List35.ListCount - 1
            If Me.List35.ItemData(i) = "" & lastPlaceID Then
                Me.List35.Selected(i) = True
            End If
        Next


 
The value of the listbox and the selected item are actually two different things. When done in the GUI the value is changed when you select an item, in code it is not. need to also set the value of the listbox

Me.List35.Selected(i) = True
me.list35.value = "" & lastPlaceID
 
BTW, if you instead set the value it does in fact also select it. So you only have to set the value. My guess is that the reason it works in one way and not another is to handle multi selections.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top