INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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 


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

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

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

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.

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

(OP)
Thank you

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close