title: Querying an Access table using the value selected in a combo
body: <p>I have started to build the application where I can navigate through a table in Access and bring in three text boxes the ProjectID, ProjectName and ProjectManager. I have also added 4 buttons (MoveNext, MoveBack, MoveFirstRecord and MoveLastRecord) that work.</p>
  
  <p>At the moment, when I load the application I am able to navigate through the records and display in the text boxes the Project Name, Project ID and Project Manager. I can also move next, move back, move to the first record and move the last one without problems.</p>
  
  <p>I have also managed to add a combo that displays all the Projects ID, which are always unique.</p>
  
  <p>What I need to do is, by choosing a Project ID from that combo box and then clicking on a new button called "Search Project", to fill the text boxes with the appropriate information for the Project ID chosen in the combo.</p>
  
  <p>I am quite lost and I don't know how to approach this in a efficient way.</p>
  
  <p>This is the code I currently have:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class Form2
      Dim connection As New OleDb.OleDbConnection
      Dim DataSet As New DataSet
      Dim DataAdapter As OleDb.OleDbDataAdapter
      Dim sql1 As String
      Dim sql2 As String
      Dim inc As Integer
      Dim MaxRows As Integer
  
      Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Try
              connection.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Corporate Reporting\2014_15\Corporate\QuarterlyReporting.accdb"
              connection.Open()
  
              '--For the text boxes--
              sql1 = "SELECT * FROM Projects_Application"
              DataAdapter = New OleDb.OleDbDataAdapter(sql1, connection)
              DataAdapter.Fill(DataSet, "Projects")
  
              '--For the combo--
              sql2 = "SELECT ProjectID FROM Projects_Application ORDER BY ProjectID"
              Dim cm As New OleDb.OleDbCommand(sql2, connection)
              Dim dr As OleDb.OleDbDataReader = cm.ExecuteReader
              While dr.Read
                  cmbSearch.Items.Add(dr(0).ToString)
              End While
  
              dr.Close()
              connection.Close()
  
              MaxRows = DataSet.Tables("Projects").Rows.Count
              inc = -1
          Catch ex As Exception
              MsgBox(ex.Message)
          End Try
      End Sub
  
      Private Sub NavigateRecords()
          txtProjectName.Text = DataSet.Tables("Projects").Rows(inc).Item(0)
          txtProjectID.Text = DataSet.Tables("Projects").Rows(inc).Item(1)
          txtProjectManager.Text = DataSet.Tables("Projects").Rows(inc).Item(2)
      End Sub
  
      Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
          If inc &lt;&gt; (MaxRows - 1) Then
              inc = inc + 1
              NavigateRecords()
          End If
      End Sub
  
      Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
          If inc &gt; 0 Then
              inc = inc - 1
              NavigateRecords()
          End If
      End Sub
  
      Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
          If inc &gt; 0 Then
              inc = 0
              NavigateRecords()
          End If
      End Sub
  
      Private Sub bntLastR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntLastR.Click
          If inc &lt;&gt; (MaxRows - 1) Then
              inc = MaxRows - 1
              NavigateRecords()
          End If
      End Sub
  
      Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
          ??? ???
      End Sub
  End Class
  </code></pre>