Results 1 to 2 of 2
  1. #1
    sarcher is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    9

    Setting focus to an ID in a LISTBOX

    I have a Listbox that I would like to set focus to a specific RECORD_ID.
    I have a process to where i bring up a form to add a new item to the Listbox an upon returning I would like for the Listbox to go to that specific record so I don't have to scroll down.

    This is what I tried to use (on close button)



    Private Sub Command4_Click()
    Dim P_num As Integer
    P_num = Me.ID_Project
    DoCmd.Close
    Forms![Finance Project Tracking]!List6.Requery 'Requeries the listbox
    Forms![Finance Project Tracking]!List6.Selected(P_num) = True
    End Sub

    Probably need a SetFocus or something

    Thanks
    Stephen

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,125
    I think you want to use ItemData, have a look at the code below:
    Code:
    Public Sub ListboxSelectString(lstListbox As ListBox, strToSelect As String, Optional SelectDeselect As Boolean = True)
        Dim i As Integer
        For i = 0 To lstListbox.ListCount - 1
            If lstListbox.ItemData(i) = strToSelect Then
                lstListbox.Selected(i) = SelectDeselect
            End If
        Next i
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-17-2014, 01:04 PM
  2. Replies: 8
    Last Post: 03-01-2014, 02:15 PM
  3. Setting the focus on a subform
    By Paul H in forum Forms
    Replies: 3
    Last Post: 01-10-2012, 09:17 AM
  4. Setting focus on a tabbed form
    By crowegreg in forum Forms
    Replies: 21
    Last Post: 08-27-2011, 09:22 AM
  5. Setting Focus on a Form
    By MFeightner in forum Forms
    Replies: 1
    Last Post: 07-30-2009, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums