Results 1 to 4 of 4
  1. #1
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130

    Listbox Items Shown Twice

    Code:
    Private Sub Form_Load()   Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim strSQL As String, strItem As String
       
       DoCmd.GoToRecord acDataForm, "frmAddClassRoster", acNewRec
       
       strSQL = "SELECT ID, FirstName, LastName, SSN FROM tbl1Students"
       Set db = CurrentDb
       Set rs = db.OpenRecordset(strSQL)
       Do Until rs.EOF
          strItem = rs.Fields("ID").Value & ";" _
             & rs.Fields("FirstName").Value _
             & " " _
             & rs.Fields("LastName").Value _
             & " (" _
             & rs.Fields("SSN").Value _
             & ")"
          Me.lstAllStudents.AddItem strItem      ' Row Source Type must be Value List
          rs.MoveNext
    
    
       Loop
       
      rs.Close
       Set rs = Nothing
       Set db = Nothing
    End Sub
    The listbox is displaying the proper information, but it shows all the entries twice. The top of the list shows all items with just First and Last name. IT then repeats the list with the (SSN) behind the name. The second portion is what I would like it to display. How can I have it get rid of the other entries?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps you need to clear the list. There is a function here that might help.
    https://msdn.microsoft.com/EN-US/lib.../ff194439.aspx

  3. #3
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130
    That helped lead me in the right direction. I went with the following code instead tho. Added it before the form load added the new information.
    Code:
    Dim i As Integer
    For i = 1 To ListBox1.ListCount
    'Remove an item from the ListBox.
    ListBox1.RemoveItem 0
    Next i

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Glad you were able to find a solution and post the solution here.

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

Similar Threads

  1. Adding all items in ListBox
    By Voodeux2014 in forum Programming
    Replies: 12
    Last Post: 11-10-2015, 01:31 PM
  2. Tallying a listbox's items
    By lyrasphere in forum Access
    Replies: 3
    Last Post: 05-22-2014, 08:12 AM
  3. Replies: 1
    Last Post: 09-11-2012, 11:49 PM
  4. Filter items shown in Combo Box in sub-form
    By mikeha_99 in forum Access
    Replies: 2
    Last Post: 06-14-2011, 12:54 PM
  5. Replies: 8
    Last Post: 05-24-2011, 03:41 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