title: issue with ms access vba in listbox index and setfocus changing on click
body: <p>Hopefully you can help me. I have a form bound to a query, in which navigation is directly related to a list box and a Next and Previous set of buttons I created. On Load I select the first row in the list box and the focus also is automatically being set on the same first row; consequently, when I select that first row, I take the unique ID of the record and clone the recordset so that I can display it on the form. As I update the records on the form, via a textboxes and drop-downs, when the record meets a certain criteria, then it's deleted from the table and added to another table. 
  So, after deleting the record, I try for the list box to have the same row selected; which, after requerying, now should show the very next record. The problem is that the listindex changes and if I pull it up on the Immediate Window it shows the index number from the previously clicked-on row, with the dotted line around it, but not the actually selected and blacked out row. 
  I know the listbox.setfocus command was giving me that issue, but I took all of the setfocuses out and it helped, however now users can't use the mouse wheel since the list box is not onfocus. Also, the dotted line appears again after you click on the scroll bar on the right side.</p>
  
  <p>The AfterUpdate code moves the record when it's completed. There is a move_completed procedure in there but it's only used to run the sql needed to move the record to an archive table upon completion. If I can't get the listbox and the form synchronized then records don't move correctly due to the code not picking up the right unique ID in order to move them. </p>
  
  <p>Any help is much appreciated; let me know if I'm missing any code ;)</p>
  
  <pre><code>     Private Sub Form_Load()
          With Me
          'I populate the hidden text box below in order to keep a reference as data is updated and use it when we need to do requeries
             .txtCurrentFile.Value = Forms!frmSelectPT.cboSelectPTFile.Value
             'QRecSel is the name of the listbox which is now being populated, onload
             .QRecSel.RowSource = "" &amp; _
                "SELECT P.ID, P.[Member Number], P.[Member SSN], P.[Last Name] &amp; ', ' &amp; P.[First Name] AS [Mbr Name], P.DOB, " &amp; _
                   "P.[Member Eff Date], P.HRID, P.[Date Completed], P.[Enrollment Rep], P.[Edit Worked], P.Comments " &amp; _
                "FROM sqPTRecSource AS P " &amp; _
                "WHERE (((P.[File Name])='" &amp; .txtCurrentFile &amp; "'));"
          End With
          'Here we move to the first row and subsequently will make the form's record to the first row selected
          Call MoveToFirstOnlist
  
       End Sub
  
  
       Sub MoveToFirstOnlist()
          Dim rs As DAO.Recordset, strEditRcdID As String
          'I will now select top row, since my listbox has no headders, then it's 0,0
          Me!QRecSel.Selected(0) = True
          'I noticed this line is a little redundant, since the listbox bound column is column "0" anyways, but it works for me when I pull the ID
          strEditRcdID = Nz(Me.QRecSel.Column(0), 0)
          Set rs = Me.Form.RecordsetClone
          rs.FindFirst "[ID] = " &amp; strEditRcdID
          Me.Form.Bookmark = rs.Bookmark
  
       'Cleanup
          Set rs = Nothing
          strEditRcdID = ""
       End Sub
  
       Private Sub cmdNext_Click()
          With Me.QRecSel
             If IsNull(Me.QRecSel.Column(0, (.ListIndex) + 1)) = False Then
                Me.QRecSel.Selected((.ListIndex) + 1) = True
                QRecSel_Click
             Else
                MsgBox "The last edit is already selected!"
             End If
          End With
       End Sub
  
       Private Sub cmdPrevious_Click()
          Dim lngIndex As Long
  
          With Me.QRecSel
             lngIndex = .ListIndex
  
             If lngIndex &gt; 0 Then
                .Selected(lngIndex - 1) = True
                QRecSel_Click
  
             ElseIf lngIndex = 0 Then
                MsgBox "The first edit is already selected!"
             End If
          End With
       End Sub
  
       Private Sub QRecSel_Click()
           Dim rst As DAO.Recordset, varID As Variant
           RunCommand acCmdSaveRecord
           varID = "'" &amp; Me!QRecSel.Column(0) &amp; "'"
           Set rst = Form.RecordsetClone
           rst.FindFirst "cstr([ID]) = " &amp; varID
           Form.Bookmark = rst.Bookmark
  
          Set rst = Nothing
          varID = ""
       End Sub
  
  Private Sub cboEditWorked_AfterUpdate()
     On Error GoTo Error_Handler
     Dim strCurrRecID As String, lngRow As Long, lngLastIndex As Long, strLastRowSource As String
     With Me
        strCurrRecID = .QRecSel.Column(0)
        If .cboEditWorked.Value = "Yes" Then
           If .cboEnrollmentRep.Value = "" Or IsNull(.cboEnrollmentRep) = True Then
              MsgBox "Please pick 'Enrollment Rep' from list", vbCritical, "No Enrollment Rep!"
              .cboEditWorked.Value = "No"
              RunCommand acCmdSaveRecord
           ElseIf .cboEnrollmentRep.Value &lt;&gt; "" Or IsNull(.cboEnrollmentRep) = False And .cboEditWorked.Value = "yes" Then
              .txtDateCompleted.Value = Format(Date, "MM/DD/YYYY")
              RunCommand acCmdSaveRecord
              lngLastIndex = .QRecSel.ListIndex
              strLastRowSource = .QRecSel.RowSource
              Move_Completed .cboEnrollmentRep, .cboEditWorked, .QRecSel.Column(0), "tbl_MEI_PT_ARCHIVE", _
                 "tbl_MEI_PT_WORK", "ID"
              .QRecSel.Requery
              If .QRecSel.ListCount &gt; 0 Then
                 .QRecSel.Selected(lngLastIndex) = True
                 QRecSel_Click
              Else
                 If .QRecSel.ListCount &gt; 0 Then
                    Call MoveToFirstOnlist
                 End If
              End If
           End If
        End If
     End With
  
  Exit_Here:
     strCurrRecID = "": lngRow = 0: lngLastIndex = 0
     Exit Sub
  
  Error_Handler:
     Resume Exit_Here
  
  End Sub
  </code></pre>