Search code examples
sqlvbams-accesssyntax-errorsql-insert

it gives an error when i run a SQL script


I'm trying to INSERT INTO with SQL in a table in VBA but it gives a error while running this script. why?

I was expecting it to add the values to the table but it gives an error instead, does anyone has the solution for this?

DoCmd.RunSQL "INSERT INTO tblScores (Student, Score, Date, ExamType, Lesson) VALUES (cbStudent.Value,txtScore.Value,txtDate.Value,cbExamType.value,cbLesson.Value);"

The error message:

this is the error it gives


Solution

  • Try this: Dim varStudent as String . varStudent = cbStudent . In SQL String: VALUES ( '" & varStudent & "', '" & varTxtScore & "'

    '" = SingleQuote DoubleQuote