title: MS Access VBA - First Record In List is Overwritten on Form Close?
body: <p>I just learning how to create forms in Microsoft Access 2013 and using VBA programming to control but I'm having an issue I don't quite understand.</p>
  
  <p>I have created a form with a <code>List Box</code> where the source originates from a query that contains the following fields the Query Builder in order from left to right:</p>
  
  <pre><code>   |ParentNumber|ParentName|ChildNumber|ChildName|
     |------------|----------|-----------|---------|
     |------------|----------|-----------|---------|
     |------------|----------|-----------|---------|
  </code></pre>
  
  <p>Some fields from the Query are hidden with a Column Width of <strong>0"</strong>.</p>
  
  <p>I also have 4 <code>Text Box</code> below the <code>List Box</code> corresponding to the appropriate <code>ParentNumber, ParentName, ChildNumber, and ChildName</code> values.</p>
  
  <p>When I select a record in the <code>List Box</code>, it populates the data to the appropriate <code>Text Box</code>.</p>
  
  <p>When the form first loads, the first row in the <code>List Box</code> is selected:</p>
  
  <pre><code>Private Sub Form_Load()
  
  On Error Resume Next
      DoCmd.GoToRecord , , acFirst
      Me.List = Me.List.ItemData(0)
  End Sub
  </code></pre>
  
  <p>The <strong>issue</strong> is that if I select a different row, then <strong>close</strong> the form, and <strong>reopen</strong> the form, the first row in the <code>List Box</code> is overwritten with the last <strong>selected</strong> row before the form is closed.</p>
  
  <p>Even if I start out with any other row selected <strong>initially</strong> when the form opens, the <strong>first</strong> row is always overwritten by the last selected row when the form is closed.</p>
  
  <p>The following subroutine handles the update of the <code>Text Box</code> data:</p>
  
  <pre><code>Private Sub List_AfterUpdate()
      Dim rowIndex As Integer
      rowIndex = Me.List.ListIndex
  
      Me.textBox_ParentNumber = Me.List.Column(3, rowIndex)
      Me.textBox_ParentName = Me.List.Column(4, rowIndex)
      Me.textBox_ChildNumber = Me.List.Column(6, rowIndex)
      Me.textBox_ChildName = Me.List.Column(7, rowIndex)
  End Sub
  </code></pre>
  
  <p>I found a somewhat similar problem to mine, but I tried the suggested solution, which didn't seem to work: <a href="https://stackoverflow.com/questions/32595220/ms-access-first-record-in-table-is-overwritten-on-form-close">MS Access - First record in table is overwritten on form close</a></p>
  
  <p>I'm completely baffled as to what could cause this based on the code above.</p>
  
  <p>What's my issue?</p>
  
  <p>Thanks.</p>