title: Next button to navigate Access database rows
body: <p>I have code for when you press next button it scrolls through the database rows but i want it to display an error once it hits the last row and when you hit next it cant go any further as its the last row but it seems to keep looping on me and never ends when i hit the next button? Any ideas?
  I have a variable which is = to -1 on formload.</p>
  
  <p>Code:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub searchclickbinds()
      If con.State = ConnectionState.Closed Then con.Open()
      'create data adapters
      sql = "Select * from tbl"
      da = New OleDbDataAdapter(sql, con)
      da.Fill(ds, "tbl")
      RecCnt = ds.Tables("tbl").Rows.Count   'how many records in ds
  
      TxtCI.Text = ds.Tables("tbl").Rows(inc).Item(0)
  
      Dim word
      word = ds.Tables("tbl").Rows(inc).Item(15)
  
      con.Close()
  End Sub
  </code></pre>
  
  <p>Caller:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles BtnNext.Click
      If inc &lt;&gt; RecCnt - 1 Then
          inc = inc + 1
          nclick()
      End If
  
  End Sub
  </code></pre>
  
  <p>Formload:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub main_Load(sender As Object, e As EventArgs) Handles Me.Load
      inc = -1
  End Sub
  </code></pre>