Results 1 to 5 of 5
  1. #1
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23

    ListBox Selected Record

    I am attempting to pull the information from the selected record so I can update my forms text boxes and for additional functionality later on.
    I am experiencing a couple of issues. I found this code online and I would think it would work, but I never see the message box saying "test".


    The second issue is how do I pull the data from the selected record so I can save it into a variable for later manipulation?
    Code:
    Private Sub List16_Click()
        Dim i As Integer
        For i = 0 To List16.ListCount - 1
            If List16.Selected(i) Then
                MsgBox "test"
            End If
        Next i
    End Sub
    Any help is always appreciated, I am also somewhat new to Access, so I would appreciate the info being dumbed down for me.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Is your listbox set for multi-select? If not, don't need the looping structure.

    Post the listbox RowSource sql statement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23
    I just looked up multiselect and it is set to no which is correct (i think) I just want them to click one at a time.
    I am just unclear on how to use the currently selected item within the list box.

    I would think something like this would work, but I know I am just unfamiliar with the VBA/Access language.
    Code:
    Me.textBox = List16.selectedItem[certainColumn]
    Here is the requested SQL statement
    Code:
    SELECT [queryComputerStatus].[Barcode], [queryComputerStatus].[Computer].[Manufacturer], [queryComputerStatus].[firstName], [queryComputerStatus].[lastName], [queryComputerStatus].[checkOut] FROM queryComputerStatus;

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You can either set textboxes = to columns of listbox or set variables in VBA. Refer to columns by index. Index begins with 0. With single-select listbox, expressions in textboxes could be:
    =
    [List16]
    =
    [List16].[Column](1)
    =
    [List16].[Column](2)
    =
    [List16].[Column](3)
    =
    [List16].[Column](4)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23
    HAHAHA, I am so dumb, I JUST found the answer and was coming back to post that I found it after about 30 min of Googling. =P
    Thank you again June7 for your Extremely fast and awesome responses. =)
    -Bahalzamon

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

Similar Threads

  1. Listbox.Selected not working
    By Dave D in forum Programming
    Replies: 11
    Last Post: 07-16-2014, 02:14 PM
  2. Replies: 9
    Last Post: 08-16-2013, 01:49 AM
  3. Replies: 3
    Last Post: 02-13-2012, 08:14 AM
  4. Replies: 3
    Last Post: 11-29-2011, 12:54 AM
  5. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 PM

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