title: Syntax error on INSERT INTO ... SELECT statement (Access SQL)
body: <p>I am trying to insert a field '<strong>SID</strong>' Value into <strong>tbl1</strong>, But to get the <strong>SID</strong> It must reference the forename and surname to another table (<strong>tbl2</strong>) to get the <strong>SID</strong>, I then have used the following SQL Statement and subsequent code.</p>
  
  <pre><code>    Dim sqlquery As String = "INSERT INTO tblPayments (StudentID,Payment,PaymentDate) VALUES (SELECT StudentID FROM tblStudents WHERE Forename = @Forename AND Surname = @Surname , Payment = @SPaid, PaymentDate = @todaysdate)"
  
      Dim sqlcommand As New OleDbCommand
      With sqlcommand
  
          .CommandText = sqlquery
  
          .Parameters.AddWithValue("@SPaid", Paidtxt.Text)
          .Parameters.AddWithValue("@todaysdate", Today.Date)
          .Parameters.AddWithValue("@Forename", Forenametxt.Text)
          .Parameters.AddWithValue("@Surname", Surnametxt.Text)
  
          .Connection = conn
  
          .ExecuteNonQuery()
      End With
      MsgBox("query executed, closing connection")
      conn.Close()
  </code></pre>
  
  <p>Yet, the SQLQuery is giving the error :</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Data.OleDb.OleDbException'
    occurred in System.Data.dll
         Additional information: Syntax error in query expression 'SELECT StudentID FROM tblStudents WHERE Forename = @Forename AND Surname =
    @Surname'.</p>
  </blockquote>
  
  <p>But I can not see what is wrong with the part of the statement that is specified as wrong, can someone tell me where its wrong please?</p>